How do you drop a table?
DROP TABLE is used to delete a table in SQL. It completely removes the table along with all its data and structure.
Syntax:
sql
DROP TABLE Table_Name;Example:
sql
DROP TABLE Employees;Important
- Once the command runs, every piece of data in the table is irreversibly deleted.
- If a table has relationships via foreign keys, some DBMSs will require those relationships to be removed first, or
CASCADEto be used to remove dependent objects.
An example with removing dependent objects (PostgreSQL):
sql
DROP TABLE Employees CASCADE;The takeaway:
DROP TABLEis used only once a table is no longer needed, since recovering the data will be impossible without a backup.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.