Computer Science · Ch 9 — Structured Query Language (SQL)
DROP Statement
DROP Statement
The DROP Statement
The DROP statement is SQL's way of permanently removing a database object — either a table or the entire database itself — from the system. Unlike DELETE which removes rows but keeps the table structure, DROP wipes out the object completely. This is a destructive command: once executed, the action cannot be undone. There is no recycle bin or undo button in SQL. That is why you must be extremely cautious before using it.
Dropping a Table
To remove a specific table and all its data, structure, and indexes from the database, use:
DROP TABLE table_name;
Replace table_name with the actual name of the table you want to delete. After this command runs, the table no longer exists — any queries against it will fail with an error.
Dropping a Database
To remove an entire database — including every table, view, and other object inside it — use:
DROP DATABASE database_name;
Dropping a database is far more destructive than dropping a single table. It removes all tables within that database in one irreversible step. There is no partial recovery — the entire database and its contents are gone.
Key Points to Remember
- Permanence: The
DROPstatement is irreversible. Once executed, the data is lost permanently unless you have a backup. - Cascading effect: Dropping a database automatically drops every table inside it — you do not need to drop tables individually first.
- No confirmation: Standard SQL does not prompt for confirmation. The command executes immediately upon submission.
- Use with caution: Always double-check the object name before running
DROP. A common safeguard is to first run aSELECTorSHOW TABLESto verify you are targeting the correct object.
Comparison: DROP vs DELETE
| Statement | What it removes | Can it be undone? | Effect on structure |
|-----------|----------------|-------------------|---------------------| …