views:

112

answers:

1

can anybody provide me list of all diffrences between truncate and delete in SQL server?

+13  A: 

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

Shantanu Gupta
Right. Truncate is DDL, Delete is DML.
Konerak
what about table structures?
VenkatReddy.Ravu
dont hesitate im new to sql server and even learner.
VenkatReddy.Ravu
... also, TRUNCATE cannot be used on a table referenced by a foreign key constraint.
Joe
Thx for updating answers, me too editing your comments in answer to make it more complete
Shantanu Gupta
Thanks Gupta,your 7th diffrence makes some what valuable than other and its a new one to learn.
VenkatReddy.Ravu
@Konerak: "Truncate is DDL" this is new for me, i didn't knew it before. Thx
Shantanu Gupta
@Gupta,what about table structures in both cases?
VenkatReddy.Ravu
@Venkat: I have specified that in para below points
Shantanu Gupta
Now it's googlable
Konstantin Spirin
Thx for all of your contribution to make this answer helpfull and more meaningfull.
Shantanu Gupta
Thx Shantanu for such a beatiful explanation.I recorded it safely.
VenkatReddy.Ravu
Cool, I get to trigger the *Enlightened* badge with my upvote!
Patrick Karcher
@Patrick: Thx for triggering Enlightened Badge
Shantanu Gupta