SQL Lesson 18 - Dropping tables

In some rare cases, you may want to remove an entire table including all of its data and metadata, and to do so, you can use the DROP TABLE statement, which differs from the DELETE statement in that it also removes the table schema from the database entirely.

Drop table statement

DROP TABLE IF EXISTS mytable;

Like the CREATE TABLE statement, the database may throw an error if the specified table does not exist, and to suppress that error, you can use the IF EXISTS clause.

In addition, if you have another table that is dependent on columns in table you are removing (for example, with a FOREIGN KEY dependency) then you will have to either update all dependent tables first to remove the dependent rows or to remove those tables entirely.

Exercise

We've reached the end of our exercises, so lets clean up by removing all the tables we've worked with.

1. We ve sadly reached the end of our lessons, lets clean up by removing the **Movies** table
	1. DROP TABLE IF EXISTS movies;
2. And drop the **BoxOffice** table as well
	1. DROP TABLE IF EXISTS BoxOffice;

Exercise 18 — Tasks

1. We ve sadly reached the end of our lessons, lets clean up by removing the **Movies** table ✓
2. And drop the **BoxOffice** table as well ✓

This webpage is SQL Lesson 18: Dropping tables from SQLBolt, which explains how to use the DROP TABLE statement in SQL to permanently remove an entire table—along with all its data and schema—from a database. The lesson contrasts DROP TABLE with DELETE, noting that DROP TABLE removes both the data and the schema, whereas DELETE only removes data. It also introduces the IF EXISTS clause to suppress errors if the table does not exist.

The lesson concludes the SQLBolt course series, asking users to practice by dropping the two tables they've been working with: Movies and BoxOffice. The page also reminds users about dependencies like foreign key constraints that may require handling before dropping a table. Sample data from both tables are provided as context for the exercises.

1