Drop Database and Table in MySQL

Dropping the Database

To delete an entire database, use the DROP DATABASE command. This command will delete the database and the tables inside it. Let’s try some example:

Syntax of DROP DATABASE command:

DROP DATABASE database_name;

Where: database_name is the name of the database you want to drop or delete.

Example you want to drop the workers database, issue the command:

DROP DATABASE workers;

Note: this command will wipe out all the records (tables, rows, etc.). You should be aware of what you are doing.

Dropping the Tables

DROP TABLE statement will do the job in deleting a table in your database.

Syntax:

DROP TABLE table_name;

Where: table_name is the name of the table you want to remove.

Let’s try to delete the user table. Issue the command:

DROP TABLE user;

Note 1: this will delete the user table permanently.

Note 2: you can delete multiple tables in a single query. Issue the command:

DROP TABLE table1, table2, table2;

Where: table1 is the name of first table, table2 the second table and so on and so forth.

Reminders: you should have a backup of your database and tables before you delete it.

, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.