SQLite DROP TABLE Keyword
The SQLite DROP TABLE keyword is used to delete a table from the database. It drops all the data, indexes, triggers, constraints and permission specifications for the specified table.
Syntax
The syntax of using DROP TABLE keyword is given below:
DROP TABLE [IF EXISTS] table_name;
The IF EXISTS is an optional parameter that conditionally drops table only if it exists on the database. If a table is deleted which does not exist, it will raise an error.
Example:
Consider a database containing a table called Employee with the following records:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
The description of the table can be checked using pragma table_info statement as shown below:
pragma table_info('Employee');
This will produce the result as shown below:
cid | name | type | notnull | dflt_value | pk |
---|---|---|---|---|---|
0 | EmpID | INT | 1 | 1 | |
1 | Name | VARCHAR(255) | 1 | 0 | |
2 | City | VARCHAR(100) | 0 | 0 | |
3 | Age | INT | 0 | 0 | |
4 | Salary | DECIMAL(18,2) | 0 | 0 |
To delete this table, the statement is shown below:
DROP TABLE Employee;
After dropping the table, the pragma table_info statement will return NULL:
pragma table_info('Employee'); Result: NULL
❮ SQLite Keywords