How to drop a table with MySQL

Posted in MySql -

This post shows the SQL query for dropping a table with MySQL and also some screenshots showing how ot drop a table using phpMyAdmin.

SQL Query

If the table to be dropped is called "test", run the following query to delete the table. This is irrecoverable and there is no prompting to see if you really do want to drop the table.

DROP TABLE test;

Using phpMyAdmin

If you have phpMyAdmin installed you can easily drop a table. It pays to be very careful when dropping a table with phpMyAdmin as it is trivially easy to drop the entire database by mistake. I have personally done this a couple of times myself.

Once you are looking at the table itself in phpMyAdmin the tabbed navigation will show a "Drop" entry in red on the far right. I've circled this in red in the example screenshot below.

Note the green arrow; this highlights what you need to look out for before clicking the "Drop" link. If a table name is listed then it's a table that will be dropped.

drop a table with mysql using phpmyadmin

If there's no table name specified, as shown in the next screenshot below, then clicking "Drop" will drop the entire database. So be very careful.

this will drop the whole database

After clicking "Drop" a Javascript prompt will pop up as shown below to ensure you really do want to delete the table.

confirmation dialog before the table is dropped

Click "OK" and the table will be dropped.



Related posts:


Comments