C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » Databases »

Difference B/W Truncate,Delete and Drop Table


Posted Date: 19 Jun 2008    Resource Type: Articles    Category: Databases
Author: Gaurav AgrawalMember Level: Silver    
Rating: 1 out of 5Points: 5



DROP : Drops the table records and structure from the DB schema. Nothing else is leftout. Can't rollback.

Truncate
: Clears the records from the table but the table structure still remains.
Can't roll back. Clears all records from the table because we can not use where clause in truncate command.It is fast because it delete all rows at a time not onr by one.and will make only one entry in log file for deleting all the row, THAT ALSO WE CAN ROLL BACK. it will reset Identity value of the identity column

Delete from
: deletes the rows based on the query or will delete all the rows if no "where" clause is given. Can roll back i.e deleted records can restored. it will not reset identity value of identity column
This operation is slow as compared to drop and truncate command because it makes a entry for every deleted row into the transaction log file and all deleted records can be rolled back after deletion.
in delete it will make one entry for each row to be deleted. while truncate will make only one entry for all the rows. in delete it will free all the datapages by deleting the contents of the data pages. while in truncate it will delete the pointer to those datapages for all deleted rows



Responses

Author: sangeetha    12 May 2009Member Level: Gold   Points : 2
DELETE TABLE is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the deallocation of the data pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back.

DROP : Drops the table records and structure from the DB schema. Nothing else is leftout. Can't rollback.




Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
SQL Server  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Difference between stored procedure and functions in SQL Server
Previous Resource: SQL Server Compute and Compute By Clause
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use