DROP TABLE permanently removes one or more tables—including all data, indexes, and privileges—from a MariaDB database.
DROP TABLE permanently removes a table definition, its rows, indexes, and privileges from the current database. Recovery is impossible without a prior backup, so use the command only when the table is truly obsolete.
Write DROP TABLE tbl_name;
to delete a single table. Add IF EXISTS
to suppress errors when the table is missing, TEMPORARY
to remove a temp table, and RESTRICT
or CASCADE
to control foreign-key handling.
DROP TABLE IF EXISTS Orders;
List tables in a comma-separated sequence. MariaDB drops them in the specified order, stopping on the first error.
DROP TABLE IF EXISTS Customers, Orders, OrderItems;
Prefix IF EXISTS
to avoid the ER_BAD_TABLE_ERROR (1051). This is essential for idempotent deployment or cleanup scripts.
DROP TABLE IF EXISTS Products;
Use CASCADE
to automatically remove dependent foreign keys. The default RESTRICT
blocks the drop when relationships exist.
DROP TABLE Orders CASCADE;
IF EXISTS
in repeatable migrations.INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
for dependencies.Running a script twice without IF EXISTS
raises errors. Always add the clause for idempotency.
The default behavior blocks the operation when child tables reference the target. Either drop the children first or specify CASCADE
.
Yes. Space is reclaimed as soon as the statement commits and the storage engine finishes cleanup.
Only if executed inside a transactional engine (e.g., InnoDB) and rolled back before COMMIT
. Otherwise, restore from backup.
Yes. Use DROP TEMPORARY TABLE temp_table_name;
. The statement affects only the session that owns the temporary table.
Yes. When you recreate the table, the counter starts over unless you explicitly set AUTO_INCREMENT to a higher value.
InnoDB supports transactional DDL. You can group several DROP and CREATE statements inside one transaction and roll them back before COMMIT.