Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

truncate & delete...newbie question

Status
Not open for further replies.

tran008

Technical User
May 14, 2003
110
US
These two statement seem to be doing the same job when purging the data from table:

truncate table table1
delete table

What is the benefit if any over using them? When should once be uses over an other?

thansk
 
Truncate is much faster because it is something you cannot recover from the transaction logs. Because this is dangerous in the wrong hands, normally only system admins have the rights to do this.

Delete is slower but can be recovered if someone accidentally deletes. Also the delete statement can have qualifiers so that only a portion of the records are deleted. Truncate will wipe out the whole table no matter what.

I personally prefer not to use truncate on a table unless I can easily recover by re-importing the data or if I want to clean out a table that had test records, so that the real records can be put in instead. Believe me you don't want to accidentally truncate the main table that your whole application is dependent on.

Questions about posting. See faq183-874
 
I can't find it but maybe someone else can. There was a extensive thread on recovering from delete/truncate transactions. It may be worth searching hard then I apparently can

____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top