﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Nakul Vachhrajani  / Deleting large number of rows from a table &amp;amp; a heap in a VLDB / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 08:52:46 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Thank-you for taking the time out and reading it. I am glad that you liked it and that my article will be helpful to your team in the future.Thanks again!</description><pubDate>Sun, 17 Mar 2013 08:56:39 GMT</pubDate><dc:creator>Nakul Vachhrajani</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>I really liked the lookup-table technique for deleting data from a clustered index.Will definitely suggest that to our dev teams going forward.Thank you for the article!</description><pubDate>Sun, 17 Mar 2013 08:40:53 GMT</pubDate><dc:creator>Marios Philippopoulos</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>A great article and constructive discussion!I do learn a lot of brilliant methods to delete very large table, but not just simply to make a where clause and wait for it to complete.</description><pubDate>Mon, 04 Apr 2011 10:39:53 GMT</pubDate><dc:creator>Stanley Chan</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Thanks Nakul! You have answered all my questions. Thanks for the response and once again, thanks for the article.</description><pubDate>Mon, 04 Apr 2011 08:03:28 GMT</pubDate><dc:creator>APP_SQL</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>[quote][b]APP_SQL (4/3/2011)[/b][hr]First of all, great article and very insightful so thanks for taking the time to write it. I do have one question about the approach you explained for deleting large quantities of data from tables with clustered index - Assuming I understood correctly, you are saying that on a daily basis (or some periodicity), move the data you would like deleted into a look-up table. Then, once a week, join the look-up table to the table that data needs to be deleted from and perform delete. And subsequently truncate the lookup table or something. So my question is - in your implementation of this, have you encountered any blocks on that big table that the data needs to be deleted from during the join? What if that big table is frequently being used by other processes? I was planning to try this out and I am somewhat of a novice so I thought I'd check before breaking anything :)Also, out of curiosity, I noticed that the look-up table that you created for deleting data from a clustered-index table itself had no clustered index, simply a non-clustered index on the column "UnixDateToDelete". Was this done for a specific reason?Thanks again for the article![/quote]Hello, APP_SQL!Thank-you for your feedback, and I am happy that you liked reading my article.As far as the concept goes, yes, you have understood correctly. Now, about your questions:Q1. Whether or not I have encountered any blocks on the tables during the periodic purge cycles?A1. Our is an on-premise system, and hence, we execute the purge during the weekly IT maintenance window provided to us by the customer (it's a configurable SQL job that does the purge). The window typically varies from 2 to 4 hours, and hence we have to be in and out of the system in about an hour for IT to do the rest of their maintenace. Because they happen during the maintenance window, all interfaces are down and hence, we have not had any blocking issues. There have been cases where we had to execute the purge online, and even then we did not face any major blocking issues.As an alternative, you may want to partition your table, and set the lock escalation to AUTO. What this will do is ask SQL Server to escalate locks to the partition, and not to the entire table.Q2. Why did I use non-clustered index on the lookup table as opposed to a clustered index?A2. No specific reason as such. Generally speaking, you can use a clustered index on the lookup table as well - no harm at all (in fact, your deletes may be even faster). In our case, we did not want to enforce any constraints or establish any relationships with the lookup table, and hence you will see that no PK-FK has been used. If your design is such that you can allow for a relationship to exist, please go ahead and use the clustered index by creating the "UnixDateToDelete" as Primary Key.I hope that I was able to answer your questions satisfactorily. If there is anything else I can help you out with, do let me know.</description><pubDate>Mon, 04 Apr 2011 00:47:35 GMT</pubDate><dc:creator>Nakul Vachhrajani</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>First of all, great article and very insightful so thanks for taking the time to write it. I do have one question about the approach you explained for deleting large quantities of data from tables with clustered index - Assuming I understood correctly, you are saying that on a daily basis (or some periodicity), move the data you would like deleted into a look-up table. Then, once a week, join the look-up table to the table that data needs to be deleted from and perform delete. And subsequently truncate the lookup table or something. So my question is - in your implementation of this, have you encountered any blocks on that big table that the data needs to be deleted from during the join? What if that big table is frequently being used by other processes? I was planning to try this out and I am somewhat of a novice so I thought I'd check before breaking anything :)Also, out of curiosity, I noticed that the look-up table that you created for deleting data from a clustered-index table itself had no clustered index, simply a non-clustered index on the column "UnixDateToDelete". Was this done for a specific reason?Thanks again for the article!</description><pubDate>Sun, 03 Apr 2011 16:54:27 GMT</pubDate><dc:creator>APP_SQL</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>I thought that might be the case, but didn't want to assume that.  Thank you for the help.</description><pubDate>Wed, 30 Mar 2011 08:52:08 GMT</pubDate><dc:creator>Read It</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>[quote][b]Read It (3/29/2011)[/b][hr]I liked the article.  I'm a bit confused by your numbers though.  You said make note of the original data and log file sizes and then show the before and after file sizes after the delete was performed.  There's a significant difference in the original file sizes to the before and after file sizes.  I'm not sure what's happening there.  Can you give me a little more explanation on those?[/quote]Hello!Good to know that you liked reading my article. I can definitely help you out in understanding the difference in the file sizes. Please find the explaination below:Case #1 - Deleting Random Data from a tableInitially, we generated our test data, and noted the file sizes. The data and log files came out to 2694MB and 1705MB respectively.Next, we generated the lookup table, and then executed the purge. The "Before" and "After" values are with respect to the Purge operation, and hence contain the space occupied by the lookup table.The above also applies to Case #2 - Deleting data from a heap (non-clustered table).The basic point I was trying to make is that the file sizes remain constant during the purge operation, and hence I have taken the file size measurements accordingly.Do let me know if you still have any doubts, and I will be more than happy to help you out.</description><pubDate>Wed, 30 Mar 2011 07:51:28 GMT</pubDate><dc:creator>Nakul Vachhrajani</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>I liked the article.  I'm a bit confused by your numbers though.  You said make note of the original data and log file sizes and then show the before and after file sizes after the delete was performed.  There's a significant difference in the original file sizes to the before and after file sizes.  I'm not sure what's happening there.  Can you give me a little more explanation on those?</description><pubDate>Tue, 29 Mar 2011 14:10:22 GMT</pubDate><dc:creator>Read It</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Thanks for the article, and the discussion, there is a lot of good information here.</description><pubDate>Fri, 25 Mar 2011 14:01:32 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Hello!Thank-you all for your interest, and valuable feedback.Some of the points mentioned in the feedback are really great. I will research them and update the article as necessary.However, for some suggestions (filtered indexes, using partitioned tables, etc) are all great in hindsight. As mentioned, this is based upon a live example, and the schema was in place and no changes were allowed (at least in the case of the heap). That being said, I agree that if a purging solution is being designed from scratch, yes, these are some of the features that absolutely should be used.</description><pubDate>Fri, 25 Mar 2011 12:26:39 GMT</pubDate><dc:creator>Nakul Vachhrajani</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Instead of chasing up purge with a frequent large delete, partition table at design time is a good option. The criteria you use in delete (whereclause) can be used for partition table key columns.See my SQLSaturday presentation.</description><pubDate>Fri, 25 Mar 2011 08:04:22 GMT</pubDate><dc:creator>jswong05</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>[quote][b]belgarion (3/24/2011)[/b][hr]Great article Nakul. Agree with all the comments about using smallish batch sizes to keep row level locks from escalating! Also, if the delete(s) involve hash matching, keeping to a small batches minimising the chances of a collision.When multiple tables must be deleted from to preserve transaction integrety, I've had some success with cascading deletes but have also had some horrors when the database design isn't sufficently normalised to make it work well.One point it would be worth adding to your article is how the purging gets implemented. While it can be run in dead time (typically overnight) not every database has this option nowadays. And if purging hasn't been done for ages then disk resources may just not be suffcient! What we've done with two of our large DB is to use the Resource Governor to limit the impact of the purge job and we just have it running all the time. It chuggs away in the background when system resources are available and grinds to a halt when they aren't. If you don't have SQL2008 and don't have the Resource Governor then about the only option(?) you have is to keep the batch size small, the queries well optimised and insert waits of 10 seconds or more to minimise the impact.Running purging jobs 24/7 has another benefit in that log files tend to stay roughly the same size whereas big overnight/weekly/monthly purging often pushes the log sizes way beyond normal growth sizes.[/quote]Wow now this is a good idea. Thanks for sharing!</description><pubDate>Thu, 24 Mar 2011 16:06:28 GMT</pubDate><dc:creator>amenjonathan</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>[quote][b]rob.lobbe-964963 (3/24/2011)[/b][hr]Also you're using SQL2008+. read up on "Filtered Indexes"Create a filtered index on your main table that contains your PK, and filters on your delete criteria. This index will be used to determine your deletion candidates, and the overhead should be minimal as the delete candidates should only be a small subset of the bulk of your data.[/quote]Good point! Sometimes the filtered index is a better approach than using a table, temporary or otherwise, to store PK values for transaction that are to be deleted.BTW ... How many DBA's get "completed" applications from development teams that have absolutely no databases purging logic at all!?! I have no idea how they get away with this.</description><pubDate>Thu, 24 Mar 2011 16:01:15 GMT</pubDate><dc:creator>belgarion</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>table locks are the killer here...Lock escallation happens @5000 rows, keep batch sizes below thisselect 1while @@rowcount &amp;gt; 0  delete top 4999 from ...(or something similar)Also you're using SQL2008+. read up on "Filtered Indexes"Create a filtered index on your main table that contains your PK, and filters on your delete criteria. This index will be used to determine your deletion candidates, and the overhead should be minimal as the delete candidates should only be a small subset of the bulk of your data.You can even monitor the size/rowcount of the Index to trigger when to start the purge - to keep the performance hit to a minimum. (or delay the start to an off-peak time) rather than using a scheduled date/time. </description><pubDate>Thu, 24 Mar 2011 15:53:20 GMT</pubDate><dc:creator>rob.lobbe-964963</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Great article Nakul. Agree with all the comments about using smallish batch sizes to keep row level locks from escalating! Also, if the delete(s) involve hash matching, keeping to a small batches minimising the chances of a collision.When multiple tables must be deleted from to preserve transaction integrety, I've had some success with cascading deletes but have also had some horrors when the database design isn't sufficently normalised to make it work well.One point it would be worth adding to your article is how the purging gets implemented. While it can be run in dead time (typically overnight) not every database has this option nowadays. And if purging hasn't been done for ages then disk resources may just not be suffcient! What we've done with two of our large DB is to use the Resource Governor to limit the impact of the purge job and we just have it running all the time. It chuggs away in the background when system resources are available and grinds to a halt when they aren't. If you don't have SQL2008 and don't have the Resource Governor then about the only option(?) you have is to keep the batch size small, the queries well optimised and insert waits of 10 seconds or more to minimise the impact.Running purging jobs 24/7 has another benefit in that log files tend to stay roughly the same size whereas big overnight/weekly/monthly purging often pushes the log sizes way beyond normal growth sizes.</description><pubDate>Thu, 24 Mar 2011 15:51:07 GMT</pubDate><dc:creator>belgarion</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Thanks for the article.</description><pubDate>Thu, 24 Mar 2011 12:34:20 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>We once had a similar problem, where we had to delete primary and child data for certain records in a batch process.  The solution worked rather well -- mark the primary table with a ToBeDeleted flag, then set up a batch job.  The batch job would run once per minute, and it was designed to delete and commit the TOP 10000 rows from the child tables joined to the primary table rows where the ToBeDeleted flag was set.  After the batch job had run for a few iterations, the ROWCOUNT would equal zero, which was the condition to delete the primary rows.Purging thus became a background process, with the load spread across many CPU cycles, not unlike garbage collection in a managed programming environment.</description><pubDate>Thu, 24 Mar 2011 10:18:13 GMT</pubDate><dc:creator>J Thaddeus Klopcic</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Well written for what it covered, but my initial expectation before reading the article was that you would touch more on techniques for handling transaction log growth and also handling child records.  I am currently working on a stored procedure that does many, many deletes and I had to set up logic to delete in chunks of 250,000 rows.  Otherwise, way to go!Mike Byrd</description><pubDate>Thu, 24 Mar 2011 09:58:16 GMT</pubDate><dc:creator>Mike Byrd</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>The explicit BEGIN TRAN, COMMIT TRAN in the batch delete is unnecessary, SQL will by default commit each individual statement, unless you put a transaction around the entire process. Totally agree about using a clustered key for batching (or a non-clustered index on a heap).Here's my simpler version of the batch delete (for both SQL 2005 and 2000):[code="plain"]--SQL 2005+DECLARE @i INTSET @i = 1WHILE @i &amp;gt; 0BEGIN    DELETE TOP (10000) FROM dbo.SuperBigTable		WHERE RecordID &amp;lt; 12345    SELECT @i = @@ROWCOUNTEND--SQL 2000DECLARE @i INTSET @i = 1SET ROWCOUNT 10000WHILE @i &amp;gt; 0BEGIN	DELETE * FROM dbo.SuperBigTable		WHERE RecordID &amp;lt; 12345    SELECT @i = @@ROWCOUNTENDSET ROWCOUNT 0[/code]Had to use this again this morning, a user tried to delete 88m rows out of a 90m row table, all in one statement. I told him not to do that :)</description><pubDate>Thu, 24 Mar 2011 08:56:43 GMT</pubDate><dc:creator>brad.corbin</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>[quote][b]alen teplitsky (3/24/2011)[/b][hr]is it better to use a non-clustered index in a large delete? i thought it was the opposite since you would be deleting data that is logically together in the tableyears ago i saw an issue where large amounts of data was inserted, deleted and modified on a non-clustered index and it cause a lot of blocking when the app changed to use multiple threads. we changed the clustered index column and the problems went away since the data that was changed was on the same pages and extents[/quote]changing the clustered index on a huge table is often simply not possible due to tlog constraints and/or time.  If your existing CI gets you a seek to deleted records that is great for you though!also, my comments are directed at the (much more common IMHO) scenario where you have a maintenance window to do the massive delete without concurrent-access issues.  That brings a whole 'nother level of headache since you need to leave all strutures in place and pay a huge overhead to log all the existing index deletes and you also have to use much smaller batch sizes to avoid long-duration locks causing unwanted blocking.</description><pubDate>Thu, 24 Mar 2011 08:51:05 GMT</pubDate><dc:creator>TheSQLGuru</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>is it better to use a non-clustered index in a large delete? i thought it was the opposite since you would be deleting data that is logically together in the tableyears ago i saw an issue where large amounts of data was inserted, deleted and modified on a non-clustered index and it cause a lot of blocking when the app changed to use multiple threads. we changed the clustered index column and the problems went away since the data that was changed was on the same pages and extents</description><pubDate>Thu, 24 Mar 2011 08:01:04 GMT</pubDate><dc:creator>alen teplitsky</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>batching with an appropriate non-clustered index seek delete plan (verify based on your batch size - or force it explicitly) can be a HUGE win in large delete scenarios.  Depending on what fraction of data you delete it is often a big win to drop other indexes and rebuild them after the deletes are finished.Gotta take exception to one thing in your article:1.Data File size - around 1GB initial, 1MB growth increment2.Log File size - around 800MB initial, 2GB growth incrementPlease don't EVER use 1MB growth rate.  Devastatingly bad external and internal fragmentation.  And for tlog sqlskills.com and kimberly tripp have very good information about tlog size/growth.  2GB growth is suboptimal.</description><pubDate>Thu, 24 Mar 2011 07:52:55 GMT</pubDate><dc:creator>TheSQLGuru</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>i was going to try this, but i don't think it will work very well with a non-clustered PK that is an identity column. and how long is the insert into the lookup table take compared to just deleting the data without referencing the lookup table? i was going to try it on a table with 100 million rows where i always delete data that is over 30 days old. populating the lookup table seems to be a problem. the data is log data from different servers.</description><pubDate>Thu, 24 Mar 2011 07:27:46 GMT</pubDate><dc:creator>alen teplitsky</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>If your database has been normalized you'll have to deal with child table records.  Ours is one of those created, initially, by a tool ( Visio I believe) and is very highly normalized.All previous attempts to do significant purging ( for example to create a small version of the production database for development )  exceeded sql server's capability due to the high degree of normalization and constraints.We do have a nightly data purge job, but it's limited to just a few tables.</description><pubDate>Thu, 24 Mar 2011 06:37:39 GMT</pubDate><dc:creator>Indianrock</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>This is a very well thought out article and well-written.But I'm with stevemash here.  You don't address locking at all in your article which is a big issue for people purging high transaction tables.I have a few suggestions: Taking smaller bites, which you mentioned, can sometimes beat the calculus of lock escalation(This has something to do with % of rows being updated/deleted and the amount of memory pressure) Disabling lock escalation is one method, but it can eat up lock memory so should be used with caution.Disable lock escalation in your session using Trace 1244 or 1211 (nuclear option)You can also jam open a transaction with an update lock like so:BEGIN TRANSELECT * FROM [dbo].[myTable] with  (UPDLOCK, HOLDLOCK) WHERE 1=0WAITFOR DELAY '10:00:00'COMMIT TRANThe lock hints start an IX lock on the table which is held for one hour.Any other transaction's table lock on dbo.myTable won't escalate past your jam (unless someone else manually uses the tablock hint)This is pretty much like using the trace flags... you could probably run out of lock memory and tank your system this way, since SQL wants to escalate, but can't.~Craig</description><pubDate>Thu, 24 Mar 2011 05:44:11 GMT</pubDate><dc:creator>SQLBOT</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Very well written article!</description><pubDate>Thu, 24 Mar 2011 05:10:17 GMT</pubDate><dc:creator>Maxim Picard</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Thank you for this post! I like the way you give the multiple alternatives, pros and cons :-)</description><pubDate>Thu, 24 Mar 2011 03:59:03 GMT</pubDate><dc:creator>Josep</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>thanks for this wonderful article :-)</description><pubDate>Thu, 24 Mar 2011 00:54:16 GMT</pubDate><dc:creator>ziangij</dc:creator></item><item><title>RE: Deleting large number of rows from a table &amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>I also faced these problems.  In our case we had a set of tables (~5) that had 25M to 50M inserts per day.  This was on Tier1 SAN and 8-way and 16-way boxes.  In our case, this was a fairly typical OLTP workload and we needed the data to be purged after around 3 days.  We also had the additional constraint that we had to purge concurrently because the system was 24x7.  Yes there were some periods of less activity (in which we ran the purge to minimize the decrease in throughput), but we still had concurrent inserts happening.When I saw your suggestions I noted the following road blocks to implementing them in my environment: 1) the lock escalation-- this is going to escalate to table locks in SQL 2005 (without undocumented trace flags), which you accpet as you set the table lock to TABLE -- although this would happen with the default setting, so I'm not sure what this statement is for.2) there are a lot of deadlock possibilities when using a secondary index to join into the clustered index to do a delete.  An X lock will be taken on the record in the secondary, and then an X on the clustered.  Which is OPPOSITE ordering from a normal insert which will take an X lock on the clustered primary index, then an X lock when inserting into the non-clustered, secondary index.  In your case, this is largely mitigated after the 5000th lock or so as the lock escalation will prevent the additional deadlock opportunities.  However, for us, the table lock escalation was unacceptable as is so we didn't do this.Here are my thoughts on this (only with regards to clustered index deletes-- I have no experience with heap deletes, and would like to hear more about why you are using heaps in the first place-- I know of only a few very narrow cases with typical hardware configurations and typical workloads where heaps are the right answer):1- the _best_ option if it works with your constraints is to utilize horizontal purging.  Data purging should be a constant time, metadata operation if you are in a high volume, high churn OLTP environment.  It just makes little sense to be wasting so many cpu cycles and log writes to handle something that is not part of "real time" processing.  SQL 2005 supports "sliding window" partitioning fairly well-- there are some problems to overcome with some scripting, but others before me did it well and have their scripts out there online.  To make this work you have to have easy groups (dates, days of the week, etc) that you can use to make your partitions.2- If you aren't using SQL 2005+ or Oracle or something that natively supports horizontal partitioning (or you aren't using the enterprise editions of these products, which include support for this) then you can approximate horizontal partitioning with views, but it is extremely messy.  I have seen this done in a number of systems, and its always a headache for the dba and the people writing the scripts to maintain it, but it doesn't always impact developers.  They program accept the schema in the view and don't care about whats under the view.3- If you can't use partitioning then if you can design the primary key to be prefixed with the date or something that is sargable to be able to purge on the clustered primary key then that is ideal.  This is _close_ to what you have suggested, but results in a plan that is insert and deadlock friendly.  Then you can mitigate escalation by "batching" the purge-- i.e. TOP n as you suggested so that no escalation occurs, hurting throughput.  If you are in an environment that can tolerate the escalation then by all means do it!4- If you can't do that, then you are stuck with secondary lookups and just have to deal with the escalation and hopefully have a window to delete that doesn't have concurrent throughput requirements.In general this is one of those things that is extremely frustrating to me about traditional RDBMSs.  In my opinion its a side-effect of the "be everything to everyone" philosophy which RDBMSs follow, which makes them less-good at any one of these behaviors.  This is a complete requirement for an OLTP data store-- and yet we have to rely on features which cost avg 120k$ (enterprise mssql) or worse (600k$+ for oracle enterprise + partitioning) just to get a simple feature like clean, simple, meta-data only purging.Steve</description><pubDate>Wed, 23 Mar 2011 23:09:54 GMT</pubDate><dc:creator>stevemash</dc:creator></item><item><title>Deleting large number of rows from a table &amp;amp; a heap in a VLDB</title><link>http://www.sqlservercentral.com/Forums/Topic1083085-2785-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/T-SQL/72606/"&gt;Deleting large number of rows from a table &amp;amp; a heap in a VLDB&lt;/A&gt;[/B]</description><pubDate>Wed, 23 Mar 2011 22:43:41 GMT</pubDate><dc:creator>Nakul Vachhrajani</dc:creator></item></channel></rss>