Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the diffrence between truncate and delete in sql server?

Can anybody provide me the list of all the differences between truncate and delete in SQL server?

like image 875
VenkatReddy.Ravu Avatar asked May 04 '10 06:05

VenkatReddy.Ravu


1 Answers

You should google it before asking.

Truncate

  1. Truncate removes all the references from database.
  2. Fast
  3. No entry in transaction log.
  4. Cannot be recovered if removed once.
  5. Page refrences are cleared.
  6. All or none
  7. Identity column gets re-initialized to seed
  8. Truncate is DDL

Truncate Table tblName

No contidion can be given

Delete

  1. Entries are made at Transaction log.
  2. Recoverable
  3. Slow
  4. Per record based deletion
  5. References are mainained in page
  6. Identity starts from its previous position
  7. DML
Delete FROM tableName

None of the two effects any structure to table. All references must be removed before performing any of the operation, although it doesn't applies to delete when used with Cascade = true for delete

like image 192
Shantanu Gupta Avatar answered Oct 14 '22 17:10

Shantanu Gupta