MySQL – TRUNCATE Table
TRUNCATE removes the entire data without affecting its structure. Typically, it is part of a DDL (data definition language) command. Generally, we use this command to delete entire data from a table without removing the table structure.
Syntax:
TRUNCATE TABLE table_name;
TABLE is actually an optional keyword:
TRUNCATE table_name;
When using the TRUNCATE command, it is important to consider the following points:
- After executing this command, the deleted data cannot be rolled back since the log isn’t maintained.
- Truncate cannot be used on a table that is referenced by a foreign key or is part of an indexed view.
- It does not operate on individual rows, so TRUNCATE does not fire DELETE triggers associated with the truncated table.
Example:
TRUNCATE employees;