can anybody provide me list of all diffrences between truncate and delete in SQL server?
+13
A:
You should google it before asking.
Truncate
- Truncate removes all the references from database.
- Fast
- No entry in transaction log.
- Cannot be recovered if removed once.
- Page refrences are cleared.
- All or none
- Identity column gets re-initialized to seed
- Truncate is DDL
Truncate Table tblName
No contidion can be given
Delete
- Entries are made at Transaction log.
- Recoverable
- Slow
- Per record based deletion
- References are mainained in page
- Identity starts from its previous position
- 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
2010-05-04 06:46:25
Right. Truncate is DDL, Delete is DML.
Konerak
2010-05-04 06:47:38
what about table structures?
VenkatReddy.Ravu
2010-05-04 06:49:02
dont hesitate im new to sql server and even learner.
VenkatReddy.Ravu
2010-05-04 06:49:26
... also, TRUNCATE cannot be used on a table referenced by a foreign key constraint.
Joe
2010-05-04 06:49:27
Thx for updating answers, me too editing your comments in answer to make it more complete
Shantanu Gupta
2010-05-04 06:51:12
Thanks Gupta,your 7th diffrence makes some what valuable than other and its a new one to learn.
VenkatReddy.Ravu
2010-05-04 06:52:31
@Konerak: "Truncate is DDL" this is new for me, i didn't knew it before. Thx
Shantanu Gupta
2010-05-04 06:56:02
@Gupta,what about table structures in both cases?
VenkatReddy.Ravu
2010-05-04 06:56:57
@Venkat: I have specified that in para below points
Shantanu Gupta
2010-05-04 06:58:48
Now it's googlable
Konstantin Spirin
2010-05-04 07:20:51
Thx for all of your contribution to make this answer helpfull and more meaningfull.
Shantanu Gupta
2010-05-04 07:31:23
Thx Shantanu for such a beatiful explanation.I recorded it safely.
VenkatReddy.Ravu
2010-05-05 16:13:48
Cool, I get to trigger the *Enlightened* badge with my upvote!
Patrick Karcher
2010-05-21 17:02:23
@Patrick: Thx for triggering Enlightened Badge
Shantanu Gupta
2010-05-27 09:24:57