sqlcmd.net validated sql reference
beginner defining MySQL MariaDB SQL Server PostgreSQL SQLite

Delete A Table

Permanently remove a table and all its data with `DROP TABLE`.

Docker-validated Not currently validation-green

Drop a temporary table and confirm other tables are unaffected

archive is dropped without error. The SELECT from products confirms that unrelated tables are not affected. To avoid an error if the table does not exist, use DROP TABLE IF EXISTS archive.

Rows loaded before the example query runs.
Setup
CREATE TABLE archive (id INT);

CREATE TABLE products (id INT, name VARCHAR(50));

INSERT INTO
  products (id, name)
VALUES
  (1, 'Keyboard');
Shared across supported engines.
SQL
DROP TABLE archive;

SELECT
  id,
  name
FROM
  products
ORDER BY
  id;
Returned rows for the shared example.
idname
1Keyboard

Output is identical across all engines.

Where this command helps.

  • removing a temporary or staging table after use
  • cleaning up tables that are no longer needed

What the command is doing.

DROP TABLE deletes the table definition and all rows it contains. This operation is irreversible — there is no undo. Use DROP TABLE IF EXISTS to avoid an error when the table may not exist. Dropping a table that other tables reference via foreign keys will fail unless those dependencies are removed first.