Login | Contact Us | Site Map | Resources

MYSQL Basics

Home > MYSQL Tutorial > Deleting Tables and Databases

Deleting Tables and Databases

At some point in time you might need to get rid of a MYSQL database table. A single command will get the job done, so take care to not delete the wrong table. Also, make sure that you really don't want any of the information stored in the table, because it will all be deleted as well.

The syntax to delete a table is: DROP TABLE tablename;

So, to get rid of the table that we created in our last example, we can use:

DROP TABLE pets;

...and we no longer have a place to store our pet's information.

To drop an entire database, including any tables that the database still contains, the syntax is:

DROP DATABASE databasename;

But USE WITH EXTREME CAUTION!

In order to prevent errors occurring when deleting a MYSQL table or database that may no longer exist, "if exists" can be used.

DROP TABLE IF EXISTS pets;
DROP DATABASE IF EXISTS databasename;