Course contentsShow
← Databases & SQL
Lesson 47 of 1,9531. Relational FoundationsFree lesson

Dropping and Truncating Tables

Explain the operational differences between destroying schema versus clearing all stored data.

In this lesson, you will learn how to distinguish between removing a table's entire structure and simply clearing out its contents.

When managing a database, you will eventually reach a point where data is no longer needed. Depending on whether you want to keep the "container" or dispose of the whole thing, you have two primary options: TRUNCATE and DROP.

The TRUNCATE Command

Think of TRUNCATE like emptying a trash bin. You keep the bin itself—the structure of the table, including its columns and data types—but you remove every single row stored inside it.

TRUNCATE TABLE employees;

This is an efficient, high-speed way to reset a table. Because it doesn’t delete rows one by one, it is often faster than a DELETE command. The table definition remains completely intact; you can immediately start inserting new data into the same columns without re-creating anything.

The DROP Command

DROP is much more aggressive. It is equivalent to taking that trash bin and throwing it into a furnace. It destroys the table definition entirely, including all columns, indexes, and constraints you previously defined.

DROP TABLE employees;

Once you run this command, the table no longer exists in your database schema. If you try to run a SELECT statement on that table afterward, the database will return an error because it can no longer find the object. To use the table again, you would have to start from scratch and use a CREATE TABLE statement to define its structure.

Operational Differences

  • Structure: TRUNCATE keeps the structure; DROP removes it.
  • Data: Both remove all existing records.
  • Recovery: Both are typically permanent actions, so use them with extreme caution. Always ensure you have a backup of your data before running these commands, as they cannot be easily undone.

Key Takeaway: Use TRUNCATE when you want to reset a table's contents while keeping the schema, and use DROP only when you want to permanently delete the table definition itself.