Name

DROP TABLE — Delete a table from a database

Syntax

image with no caption

Common Usage

DROP TABLE database_name.table_name;

Description

The DROP TABLE command removes a table from a database. The table and all the data it contains are permanently removed from the database. Any associated indexes and triggers are also removed. Views that might reference the table are not removed. Delete triggers will not be fired.

The DROP TABLE command may also be used to remove virtual tables. In that case, a destroy request is sent to the table module, which is free to do as it sees fit.

If foreign keys are enabled, the DROP TABLE command will perform the equivalent of a DELETE for each row in the table. This happens after any associated triggers have been dropped, so this will not cause any delete triggers to fire. If any immediate key constraints are violated, the DROP TABLE command will fail. If any deferred constraints are violated, an error will be returned when the transaction is committed.

Unless the database is in auto-vacuum mode, dropping a table will not cause the database file to shrink in size. The database pages used to hold the table data will be placed on the free list, but they will not be released. The database must be vacuumed to release the free database pages.

Dropping a table that does not exist normally generates an error. If the optional IF EXISTS clause is provided, this error is silently ignored. ...

Get Using SQLite 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.