![]() |
VOOZH | about |
The TRUNCATE TABLE statement is used to remove all records from a table while preserving its structure. It is especially useful when working with large tables.
Example: First, we will create a demo SQL database and table, on which we will use the TRUNCATE TABLE command.
Query:
TRUNCATE TABLE Students;Output:
Syntax:
TRUNCATE TABLE table_name;Here we will look at different examples of the SQL TRUNCATE TABLE command. Consider the EMPLOYEE table below for the following example:
Query:
TRUNCATE TABLE EMPLOYEE;SELECT * FROM EMPLOYEEOutput:
But let's now check whether the structure of the table is deleted or it has been preserved so we again use the DESC command to see the structure of the table and we will see that the structure remains as it is.
To better understand when to use TRUNCATE, see our detailed explanation of the differences between TRUNCATE, DELETE and DROP commands.