SQL DROP TABLE
DROP TABLE
is used to delete a table permanently from the database along with all its data. Use it carefully!
πΉ Basic Syntax
DROP TABLE table_name;
- Replace
table_name
with the name of the table you want to delete. - This operation cannot be undone β all data in the table will be lost.
πΉ Example
DROP TABLE employees;
Deletes the employees
table and all its data.
πΉ Important Notes
- You cannot drop a table if other objects depend on it (like foreign keys) without first removing dependencies.
- Some DBMS support
DROP TABLE IF EXISTS
to avoid errors if the table doesnβt exist:
DROP TABLE IF EXISTS employees;
- Be cautious when using this command in production environments.
π§ Quick Recap
Key Point | Explanation |
---|---|
Command | DROP TABLE table_name; |
Effect | Permanently deletes table & data |
Warning | Irreversible operation! |
Conditional Drop | DROP TABLE IF EXISTS (optional) |
π‘ Always double-check before dropping a table to prevent accidental data loss.