English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

SQL Delete Table (DROP TABLE Statement)

In this tutorial, you will learn how to use SQL to delete databases and tables.

Delete a table from the database

You can easily delete the database table no longer needed using the DROP TABLE statement. The DROP TABLE statement permanently deletes all data in the table and the metadata defined in the data dictionary for the table.

Syntax

DROP TABLE can be used to delete one or more tables. The following syntax can be used:

DROP TABLE table1_name,...table2_name,...;

Here,table1_name,table2_name,...is the name of the table to be deleted.

Warning:Deleting a database or table is irreversible. Therefore, be cautious when using the DROP statement, as the database system usually does not display any warnings, such as 'Are you sure you want to delete?'. It will immediately delete the database or table and all its data.

Let's try to use the DROP TABLE statement to delete the database table.

If you rememberCreated TableIn this chapter, we have alreadyDemonstrationA table was created in the databasepersons. The following statement will permanently delete the table from the database.

DROP TABLE persons;

After executing the above command, if you try to operate onPerson(personsIf you try to perform any operation on the table (such as selecting records from the table), you will receive an error message.

Delete Database

Similarly, you can use the DROP DATABASE statement to delete a database. The following command will permanently deleteDemonstrationDatabase.

DROP DATABASE demo;

Now, if you try to use the USE demo statement to selectdemoIf the database; is not specified, an error message will be received, indicating 'Unknown database' or 'Database does not exist'.