bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL Database
SQL•SQL Database

SQL DROP TABLE Statement

Concept visual

SQL DROP TABLE Statement

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

The SQL DROP TABLE Statement

The DROP TABLE

statement is used to permanently delete an existing table in a database.

Note:

Be careful before dropping a table! Dropping a table deletes the entire table and all its content!

Syntax

Drop Table

table_name

;
To prevent an error from occur (if the table does not exists), it is a good practice to add the IF EXISTS

clause:

Drop Table If Exists

table_name

;

Note:

In most databases you cannot drop a table that is referenced by a foreign key constraint in another table. To solve this, you must remove the foreign key constraint or drop the dependent table.

DROP TABLE Example

The following SQL statement drops the "Shippers" table:

Example

DROP TABLE IF EXISTS Shippers;

Sql Truncate Table

The TRUNCATE TABLE

statement is used to delete all the records in a table, but it keeps the table structure, columns and constraints.

Syntax

Truncate Table

table_name

;

Previous

SQL CREATE TABLE Statement

Next

SQL ALTER TABLE Statement