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 ...
Get MySQL for Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.