SQL DROP TABLE Statement

In SQL, DROP TABLE is used to delete the tables in our database.

Example

-- delete Shippings table
DROP TABLE Shippings;

Here, the SQL command will delete a table named Shippings.

Also, make sure you have admin or DROP permission to run this command.


DROP TABLE Syntax

The syntax of the SQL DROP TABLE statement is:

DROP TABLE table_name;

Here, table_name is the name of the table to be removed.

Note: When we delete a database table, all records within the table are also deleted.


DROP TABLE IF EXISTS

If a table does not exist, dropping it will throw an error. To fix this issue, we can add the optional IF EXISTS command while dropping a table. For example,

-- delete Orders table if it exists
DROP TABLE IF EXISTS Orders;

Here, the SQL command will only drop a table if there exists one with the name Orders.


Also Read

Did you find this article helpful?

Your path to become a builder.

Builders don’t just know how to code, they create solutions that matter. Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community