Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
DROP and TRUNCATE | DDL and DML in SQL
Intermediate SQL
course content

Course Content

Intermediate SQL

Intermediate SQL

1. Grouping
2. Nested Subqueries
3. Joining Tables
4. DDL and DML in SQL

book
DROP and TRUNCATE

It's worth mentioning two more operations in DDL: DROP and TRUNCATE.

DROP: Used to delete database objects such as tables, databases, and indexes.

TRUNCATE: Removes all rows from a table but preserves the table's structure.

We've used these operations to clear or delete tables to check tasks in previous chapters:

The DROP TABLE command will completely remove the employees table from the database. Keep in mind that this action usually requires special permissions in many database management systems (DBMS).

If you're working on a project, you might not have the necessary access rights. In the next course on Advanced Techniques in SQL, you'll learn about roles and how to manage them.

1
TRUNCATE TABLE employees;
copy

The TRUNCATE TABLE command removes all data from the employees table, leaving it empty. However, it keeps the table's structure intact, so columns and constraints remain unchanged. You will need the right permissions to perform this action in a DBMS.

Be cautious when using these commands. Without database backups, you can't undo a table deletion or data removal.

Note

Developers often use soft deletion by adding a column like is_deleted with a BOOLEAN type. When a row is 'deleted', this column is set to true (or 1). This way, you can track deleted data without losing it.

What is the main difference between `DROP TABLE` and `TRUNCATE TABLE` operations?

What is the main difference between DROP TABLE and TRUNCATE TABLE operations?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 3
We're sorry to hear that something went wrong. What happened?
some-alt