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!

Deleting all row data in a table 2

Status
Not open for further replies.

hapax

Programmer
Nov 10, 2006
105
US
What's the easiest way to remove all the row data in a table, without deleting the table itself?


 
Truncate Table MyTable

Paul
---------------------------------------
Shoot Me! Shoot Me NOW!!!
- Daffy Duck
 
Be aware that truncate can be rolled back if you do so before the transaction is committed but if you inadvertently do it to the wrong table and find out later, it may not be possible to recover from the transaction logs. Do not do this on a production machine unless you have a current backup. Also this is not a command you want to allow to run from the user interface. This is a very dangerous command and should not be run by anyone except a dba. If users need to delete all records it is far safer (but slower) to use
Code:
delete tablename

"NOTHING is more important in a database than integrity." ESquared
 
some other considerations from BOL
You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint; instead, use DELETE statement without a WHERE clause. Because TRUNCATE TABLE is not logged, it cannot activate a trigger.

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top