SQL - DROP TABLE


Advertisements

Previous Page Next Page

The SQL DROP TABLE statement is used to delete a table from the database. It drops all the data, indexes, triggers, constraints and permission specifications for the specified table.

Note: Be careful before dropping a table. Once deleted, all information stored in that table will be lost forever!.

Syntax

The syntax of the DROP TABLE is given below:

DROP TABLE table_name;

Example:

Consider a database tables called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

The description of the table can be checked using DESC command as shown below:

DESC Employee;

FieldTypeNullKeyDefaultExtra
EmpIDint(11)NoPRI
Namevarchar(255)No
Cityvarchar(100)YesNULL
Ageint(11)YesNULL
Salarydecimal(18,2)YesNULL

To delete this table, the SQL code is shown below:

DELETE TABLE Employee;

After deleting the table, the DESC command will throw following error:

DESC Employee;	
Table 'testDB.Employee' doesn't exist

Previous Page Next Page
Advertisements