Dropping tables
Dropping tables in MySQL follows the same pattern as dropping databases.
DROP TABLE <table name>;
We use the keyword DROP
so MySQL knows what we want to do. We then indicate that we want to drop a table and follow that with the name of the table to be deleted.
Note
When the DROP
command is executed, the table and its definition are deleted unrecoverably from the database. You should therefore exercise caution when using it.
It is worth noting that the user who passes the DROP
statement to MySQL must have the DROP
privilege. Otherwise, MySQL will not execute the statement.
Playing it safe
If you create a temporary table and want to ensure that only that table is dropped, use the TEMPORARY
keyword:
DROP TEMPORARY TABLE <table name>;
So to drop the araba
table defined previously, we would issue this command:
DROP TEMPORARY TABLE araba;
Of course, if we issue that command twice, MySQL will get confused. More on this is mentioned in the following section Avoiding errors.