Flash cards
Review the key moves
What is the main idea behind SQL DROP TABLE Statement?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Put the learning moves in the order that makes the concept easiest to apply.
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
;