O'Reilly logo

Sams Teach Yourself MySQL by Chris Newman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dropping Tables

To drop a table, use the DROP TABLE command followed by the name of the table. Beware that a dropped table cannot be recovered unless you have a backup.

To drop the people table you created earlier in this lesson, use the following command:

mysql> DROP TABLE people;
Query OK, 0 rows affected (0.00 sec)

You can use DROP TABLE IF EXISTS so that no error occurs if a table does not exist. This is useful in a batch script that creates all the tables for a database: The script will delete the existing tables before re-creating them but will not fall over if the tables do not exist yet.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required