Shawn Weisfeld

I find when I talk to myself nobody listens. - Shawn Weisfeld
posts - 352, comments - 144, trackbacks - 34

My Links

News

The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Archives

Post Categories

Need to delete lots of data, do it in small chunks

By adding a top clause to your delete statement you can delete a chunk of records at a time. By combining it with a while you can put it in a loop and wipe the entire table.

WHILE

EXISTS (SELECT * FROM Foo)

BEGIN

DELETE TOP(100) FROM Foo

END

Had someone send me an email telling me that it might be better to use a TRUNCATE TABLE command then this method, and in most cases this is preferable. Conversly not always do us "evil" developers get TRUNCATE permissions from our DBA's. You can read more about TRUNCATE here (http://msdn2.microsoft.com/en-us/library/aa260621.aspx).

Print | posted on Friday, April 25, 2008 6:55 PM | Filed Under [ SQL ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 1 and 8 and type the answer here:

Powered by: