Truncating SQL table refers to the process of deleting all table data quickly without affecting the table structure and without logging individual deletions. "TRUNCATE TABLE" is faster than "DELETE TABLE" statement for large data sets, making it the preferred method.
1. "TRUNCATE TABLE" statement is used to delete all table data in a database. Here's syntax :
TRUNCATE TABLE table_name;
2. As you can see in below image, [Product] table contains some records. Let's delete all table data without affecting the table structure.
3. Run below SQL statement in SSMS :
TRUNCATE TABLE [Product];
4. Above statement will delete all table data from [Product] table.
That's it! You have successfully deleted all [Product] table data using T-SQL.
Truncate table removes all rows from a table in SQL, but the table structure remains intact.
Truncate table in SQL quickly deletes all rows from a table without logging individual row deletions.
The key difference between DELETE and truncate is that DELETE removes rows one by one and logs each deletion, while truncate instantly removes all rows without logging.
The syntax of truncate table in SQL typically involves the command "TRUNCATE TABLE" followed by the table name.