SQL Server - Truncate V/S Delete

Who is online?  154 guests and 0 members
home  »  blogs  »  Satnam Singh  »  SQL Server - Truncate V/S Delete
  Rate This Blog Entry:  register  or  login

Author

singhsatnam84 Satnam Singh (Member since: 11/9/2011 3:55:30 PM)
Satnam Singh is a SQL Server DBA with Larsen and Toubro Infotech, Mumbai, India. Satnam has around 6 years of experience on Microsoft SQL Server Technology. Satnam mainly specializes in areas such as High Availability and Performance Tuning. He is a regular contributor to the SQL Server Community where he regularly posts articles discussing various scenarios of the technology. Satnam lives in South Mumbai along with his family. During his free time he loves reading books,going out on long drives etc.In case of any issues for which you feel help is required you can reach him on singhsatnam84@yahoo.com

View Satnam Singh 's profile

Comments (9)

yedaanna
6/18/2012 6:33:13 AM yedaanna said:

whats is the main diference between delete and truncate?? why recovery is possible in delete and why not in truncate ?

by
singhsatnam84
6/18/2012 6:38:39 AM Satnam Singh said:

In order to RollBack a transaction it has to be logged which is possible only in case of Deletes. Truncate never logs the removed records and hence can't be Rolled Back.

by
AhmadOsama
6/18/2012 12:05:02 PM Ahmad Osama said:

Nice article.. to add to this, Truncate can be rolled if it's inside an Explicit transaction as in

Begin tran

truncate

Rollback

by
deangc
6/18/2012 3:34:41 PM deangc said:

I think you need to be careful about your terminology. It is not true that a TRUNCATE TABLE cannot be rolled back. If you start a transactaction, issue a TRUNCATE TABLE command, and then ROLLBACK TRAN, the TRUNCATE will be rolled back. 

What you are talking about is better termed 'recovery'. A TRUNCATE TABLE command can't be recovered once a COMMIT has been issued, as you demonstrate. The word 'rollback' has a specific meaning in SQL and it isn't 'restore and rollforward'.

There are many cases where TRUNCATE is useful for production code and data. You just have to understand the implications.

by
princerastogi
6/18/2012 4:17:52 PM prince rastogi said:

nice article satnam.....

Working of Truncate Command :

When we fire truncate command for a particular table  it deallocate all the pages for that table, and transaction log have only entry of page deallocation..

by
Naginder
6/19/2012 6:18:07 AM Naginder singh virdi said:

another thing that i found out while at work today, There is no permission or privilege that you can grant a user to truncate a table. User should be owner of table/database to be able to truncate a table or syadmin obviously or at minimum should have alter table privilege.

Where as DELETE can be granted/revoked from a user for a table/database.

let me know if i am wrong...

by
Lakshmikanth
6/20/2012 11:02:31 AM Lakshmikanth said:

With respect to TRUNCATE and DELETE ---

Both TRUNCATE and DELETE Statement(s) can be rolled back when put into an Explicit TRANSACTION.

by
Nazeer Ahmed
6/22/2012 7:00:02 AM Nazeer Ahmed said:

Nice Article mentioning all details of Truncate and Delete....

by
mkumar_dba
6/27/2012 5:14:47 AM Manoj Kumar said:

Thanks Satnam..for this wonderful Article...

In Both case..Truncate or  delete  in begin trasaction mode...whenever we not commited the transaction we can roolback the data and use for as usual.

by

Leave a comment

Name:
  *  
Email:  (your email is kept secure)
 *  
Website:

example: "http://www.SQLServerGeeks.com"

 
Type the characters:
 *
 
   

Training on Microsoft Products & Technologies

Email Subscriptions

   Get the Most Recent Blogs in your inbox
Blogs RSS Feed

Satnam Singh's latest blog posts

  • In the present age, wherein I see a lot of boom in the IT Sector, many of our youngsters are keen on taking up a career in the IT Sector but at the same time, I see that there is a lot of egoism probl...
  • Recently one of our Staging Database Server hosted in the United States of America suddenly got Rebooted after which one of the database named ABC hosted on the server went into the SUSPECT mode. The ...
  • Hi Everybody, I hope you all are doing well. I would like to thank Amit Bansal, Sarabpreet Singh, entire staff at www.sqlservergeeks.com, my fellow SQL Server Professionals who have given their valuab...
  • Performing a Database Backup is a part of DBA’s life. Backups are taken to ensure that in case of any emergencies Recovery is possible. When we talk about Recovery it means that we are referring...
  • After passing out BE Computers from Mumbai University in the year 2006 my next main aim was to get a good job wherein I get an oppurtunity to work on SQL Server technology. I was crazy to work on this...
  • Career as a Database Administrator is a very exciting and a prestigious one. You hold a very big responsibility of maintaining a company's data.A lot of Senior people in your company will be having a ...
  • Many a times, we come across a situation wherein we need to understand the difference between a Truncate and Delete Command In SQL Server.In this exclusive Blog Post, Satnam Singh, an SQL Server DBA f...
  • I was recently asked to set up Transactional Replication comprising of 29 publishers as well as same number of subscribers. One interesting challenge was that the size of the distribution database sud...
  • Last month, we decided to migrate one of our Data Center located in NewYork to Los Angeles. Due to Data Center Migration, we were going to perform the following tasks: Change the IP Addresses of the n...
  • Dear Friends, Last weekend, I posted one blog on www.sqlservergeeks.com which discussed one such approach which i used on my production server to fine tune a view which was causing a heavy damage to t...
  • AS DBAs we often need to develop DML triggers to capture multiple entries which are either INSERTED, UPDATED or DELETED from a table. A few months back, I came across a situation where the Application...
Blogs RSS Feed

Latest community blog posts

  • A few days back I was resolving a memory issue which caused sql server to stop responding. I was able to figure out the issue by looking into DBCC MemoryStatus output. It was the full text search whic...
  • This is an update to the DB-Migrate ( http://www.sqlservergeeks.com/blogs/AhmadOsama/personal/797/db-migrate-a-powershell-module-to-migrate-databases ) powershell module to migrate database between sq...
  • This blog is part of the series The TSQL Classes: Stored Procedure The links to previous post are given below. http://sqlservergeeks.com/blogs/AhmadOsama/personal/762/the-tsql-classes-stored-procedure...
  • Reporting With SSRS Part 1 : In this serires of blogs, i will try to introduce you with some of the key features of the tool which will help you get on board to become a proficient report developer.If...
  • Hi Folks, I am sure that all of you would be aware about the role of Identity column in a table, i.e., it is column which keeps on incrementing without supplying the value explicitly during insertion....
  • Recently I wrote powershell scripts to move databases, logins and SQL Agent Jobs between instances. Another one I wrote was to fix orphan users. I have now combined all of these different functions in...
  • Hi SQL Geeks, Here are the blog posts by Ahmad Osama for the month of April. We would expect more of his informative blogs this month. Happy Learning! If you like our blogs do like us on Facebook at h...
  • This blog is part of the series The TSQL Classes: Stored Procedure The link to previous post are given below. http://sqlservergeeks.com/blogs/AhmadOsama/personal/762/the-tsql-classes-stored-procedures...
  • As DBAs we are always challenged of unexpected size growth of log or data files and need to shrink files based on available free space in each file. Most of the times we are stuck and do a lot of scri...
  • One of the major migration activities is to fix orphan users. Though, it can be easily fixed by sp_change_users_login procedure, however what if you need to do this for multiple servers. A powershell ...
  • This blog is part of the series The TSQL Classes: Stored Procedure. http://www.sqlservergeeks.com/blogs/AhmadOsama/personal/764/the-tsql-classes-stored-procedures-nested-proc-recursion-and-plan-cachin...