SQL DROP TABLE Statement

In this tutorial, you will learn about the SQL DROP TABLE statement with the help of examples.

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.


Recommended Readings:

Did you find this article helpful?