SQL:Truncate
lastmod 2026-01-05created 2026-01-051 edits
An SQL command that quickly deletes all data in a table in a database.
Key features
Features of TRUNCATE TABLE ...:
- Deletes all rows in the table
- Much faster than DELETE (minimizes logging and processes everything at once)
- Resets sequences such as AUTO_INCREMENT
- Does not record individual row deletions in the transaction log
CASCADE option
- Used when another table has a Foreign Key referencing the table
- Running without CASCADE raises an error because of the foreign key constraint
- With CASCADE, data in the referencing tables is deleted as well
Examples
-- CASCADE 없이 실행 (외래 키 참조가 있으면 에러)
TRUNCATE TABLE my_table;
-- CASCADE로 실행. 참조하는 테이블도 함께 삭제하는 옵션.
TRUNCATE TABLE my_table CASCADE;