Q&A
Ask and answer questions to make information more available to wider audiences.
Tristan Learson @tristanlearson   19, Jul 2023 12:00 AM
truncate statement
What is the use of TRUNCATE statement? How is it different from DELETE statement?
answers 2
 
Answer 1
Ethan Barbrow @ethanbarbrow   09, Aug 2023 03:14 PM
Difference between DELETE and TRUNCATE statement:

DELETE statement is used to remove one or more columns from a table as well as the whole table. On the other hand, the TRUNCATE TABLE statement is used to delete the whole table permanently.
TRUNCATE TABLE statement is same as DELETE statement without a WHERE clause.
DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row.
TRUNCATE TABLE removes the data by deallocating the data pages used to store the table data and record only the page deallocations in the transaction log. Hence it is faster than delete statement.
 
Answer 2
Ethan Barbrow @ethanbarbrow   09, Aug 2023 03:14 PM
TRUNCATE TABLE statement is used to delete a table permanently. It deletes all the records from the table.

Syntax:

TRUNCATE [TABLE] [database_name.]table_name;