bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/SQL/SQL Database
SQL•SQL Database

SQL DROP TABLE Statement

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

This chapter

Overview
21

Lessons

50m

Read time

1. SQL CREATE DATABASE Statement2. SQL DROP DATABASE Statement3. SQL BACKUP DATABASE Statement4. SQL CREATE TABLE Statement5. SQL DROP TABLE Statement6. SQL ALTER TABLE Statement7. SQL Constraints8. SQL NOT NULL Constraint9. SQL UNIQUE Constraint10. SQL PRIMARY KEY Constraint11. SQL FOREIGN KEY Constraint12. SQL CHECK Constraint13. SQL DEFAULT Constraint14. SQL CREATE INDEX Statement15. SQL AUTO INCREMENT Field16. SQL Working With Dates17. SQL Views18. SQL Injection19. SQL Parameters20. SQL Prepared Statements21. SQL Hosting

On this page

The SQL DROP TABLE StatementDROP TABLE ExampleSql Truncate Table