Back to cookbooks list Articles Cookbook

How to Drop a Table in SQL

Problem:

You want to remove a table from a database.

Example:

We would like to remove the table called product from the database

Solution:

DROP TABLE product;

Discussion:

If you want to remove an existing table from a database, use the statement DROP TABLE with the name of the table. In this example, we first wrote the command DROP TABLE followed by the table name (product). That’s all you need to do. This command removes the table’s data, the table structure, and other objects associated with the table (e.g. indexes, permissions, constraints, and triggers).

Keep in mind that if there are tables with foreign keys that reference the soon-to-be deleted table, you should first drop these keys or remove the relationship between tables.

Recommended courses:

Recommended articles:

See also: