Categories
Sql Server

What is difference between Delete and Truncate

What is difference between Delete and Truncate

Truncate and Delete both will be used to delete data from a table.Both the SQL statements are used to delete only the data from table but both are differ from each other in many area like syntax, performance, resource uses.

Truncate

The TRUNCATE command in SQL removes all rows from a table without logging the individual row deletions in the transaction log also you can’t use the WHERE Clause with in the TRUNCATE statement.

Truncate table hightech

Delete

The DELETE command also removes rows from a table, but it logs individual row deletions in the transaction log. You can also use the WHERE Clause with the DELETE statement to qualify which rows are to be deleted.

Delete from hightech

Delete command with where clause…

Delete from hightech where id=1

Difference between TRUNCATE and DELETE:-

Truncate Delete
1.TRUNCATE is a DDL command2.TRUNCATE is faster than DELETE

3.TRUNCATE logs deallocation of data pages in which data exists

4.TRUNCATE command takes minimum logging resources

1.DELETE is a DML command2.DELETE is slower then TRUNCATE

3.DELETE logged operation on per row basis

4.TRUNCATE command takes a lot of logging resources