How to Drop Tables and Columns with SQL

In the last article, we learned how to create a table for our database. We were working with a table of newsletter correspondents. Now, we are going to learn how to drop a table from our database.

You may recall our goal in learning the basics of SQL was to be able to create, read, update, and delete items in our database. Dropping table covers the deleting portion of that goal. But tables aren’t the only thing you can drop. You can also drop columns from a table.

How to Drop a Database Table

Whether you are using MySQL via the command line, or if you have an application using some sort of relational database management program, the syntax for the table drop will be the same.

Once logged into your program, you can use a command like this one:

DROP TABLE respondents;

In the example above, we have stuck with our former example of using our newsletter “respondents” table. This will have the effect of completely obliterating this table, and all of its data, from our database.

This a very drastic move. Let’s imagine you only wanted to remove a certain column from the table. For example, perhaps the IP address collection field was no longer needed.In that case, you can simple drop that particular column from the database.

How to Drop a Column from a Table

Here, we are going to be deleting only the IP address column from our table of newsletter respondents.

In order to do this properly, we are going to name the table we want to alter and which column we would like to drop.

ALTER TABLE respondents DROP COLUMN ip_address;

Using the above command, we have told SQL that we want to “alter” the table named respondents and drop the column named “ip_address” from it. Using this same statement, we can drop any column from our database that we require.

Christopher Maiorana Content Marketing Writer

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

Was this article helpful? Let us know!