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_namewith 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 EXISTSto 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.