what is the difference between Delete and Truncate??

2 views
Skip to first unread message

BabuLives

unread,
Sep 30, 2005, 6:38:32 AM9/30/05
to .NetIndia
what is the difference between Delete and Truncate in sql??

Post ur answers here..

Regards,
Satheesh

Selvakumar

unread,
Sep 30, 2005, 6:42:34 AM9/30/05
to Techdot...@googlegroups.com
Delete and Truncate are functionally same...

--->>Delete only deletes the specified rows in a Table....

--->>Truncate not only deletes the rows but also reclaims the memory
occupied by them!!!

Thats the major difference...

Regards,
Selva..

Thread

unread,
Sep 30, 2005, 6:51:20 AM9/30/05
to .NetIndia
Delete can be rolled back where as trucate cannot

brainstormingguys

unread,
Sep 30, 2005, 7:03:39 AM9/30/05
to Techdot...@googlegroups.com
Hai,
The major difference is the TRUNCATE never uses the roll back segments but the DELETE statement uses the rollback segments.That's why we are able to rollback the deleted records when we use the DELETE command and we give the ROLLBACK statement.
Next one is we can't use the WHERE clause in TRUNCATE but we can use the WHERE clause in DELETE.
Hope it helps you a bit.
 
Regards,
Venkatarajan A
--
Plan for the Worst,
Hope for the Best

BabuLives

unread,
Sep 30, 2005, 7:30:51 AM9/30/05
to .NetIndia
hai...
i like to add some more points to the discussions..

The user who can DELETE rows does not mean they can TRUNCATE the table.
By default, they need at least DDL_ADMIN to do that and delete triggers
are not fired when using TRUNCATE.

Regards,
Satheesh

Dhaw

unread,
Sep 30, 2005, 7:34:56 AM9/30/05
to Techdot...@googlegroups.com
If your table have identity column.And that table contains 5 rows (identity column value = 1...5)
 
now if you use DELETE statement to remove all rows and then try to INSERT a row , the identity column value = 6
but if you use DELETE statement to remove all rows and then try to INSERT a row , the identity column value = 1
 
As selva said
 
"Delete only deletes the specified rows in a Table....
Truncate not only deletes the rows but also reclaims the memory occupied by them"
 
Thanks
Skymania

Dhaw

unread,
Sep 30, 2005, 8:08:17 AM9/30/05
to Techdot...@googlegroups.com
Sorry i have mentioned both as "DELETE"...correction follows
 
If your table have identity column.And that table contains 5 rows (identity column value = 1...5)
 
now if you use DELETE statement to remove all rows and then try to INSERT a row , the identity column value = 6
but if you use TRUNCATE statement to remove all rows and then try to INSERT a row , the identity column value = 1
 

Siva CH

unread,
Sep 30, 2005, 10:46:13 AM9/30/05
to Techdot...@googlegroups.com
DELETE is a logged operation. Every Delete transcation is logged. This can be some time costly if there is  a big chunk of data being deleted for purpose in your application.
 
Where as Truncate is a non logged operation and is faster. Truncate statement can not be applied on a table with a Foreign key constraint. Truncate statement can be rolled back.
 
Regards
Siva

 
On 9/30/05, BabuLives <sathees...@gmail.com> wrote:

Bala murugan

unread,
Oct 1, 2005, 9:47:59 AM10/1/05
to Techdot...@googlegroups.com
Hi,

   I have one doubt

    Trucate statement can be rolled back or delete statement can be rolled back because in this e-mail doc  : siva ch  told truncate can be rolled back but  manish told delete can be rolled back
 .....

Regards,
bala

Selvakumar

unread,
Oct 1, 2005, 9:58:55 AM10/1/05
to Techdot...@googlegroups.com
Hii Bala,
Truncate cannot be rolled back...Where as Delete can be
rolled back..So dont get confused...

Regards,
Selva..

Shivprasad Koirala

unread,
Oct 2, 2005, 11:37:21 PM10/2/05
to .NetIndia
Yep truncate can not be rolled back as truncate do not maintain any
transaction logs. But that adds + point to truncate they are faster
than delete.
-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/

Reply all
Reply to author
Forward
0 new messages