﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Administering / SQL Server 2005  / Delete / 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>Tue, 21 May 2013 05:42:31 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]Lynn Pettis (6/12/2008)[/b][hr]Unfortunately, it doesn't look like the OP has been on SSC since yesterday morning.  Hope he checks this thread and let's us know what's happening.:cool:[/quote]I think that happens more that we like ;)</description><pubDate>Thu, 12 Jun 2008 16:08:55 GMT</pubDate><dc:creator>noeld</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Unfortunately, it doesn't look like the OP has been on SSC since yesterday morning.  Hope he checks this thread and let's us know what's happening.:cool:</description><pubDate>Thu, 12 Jun 2008 15:13:39 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]Lynn Pettis (6/12/2008)[/b][hr][quote][b]Matt Miller (6/12/2008)[/b][hr]Makes me wonder if it wouldn't be easier to just to the select...INTO on stuff you want to keep, blow out the original table and reinsert the items to keep.....I don't recall hearing how many rows would be left after this little adventure.....Either way - deleting that much in one chunk is bound to jam things up a bit.  Perhaps deleting in smaller chunks would help, too.[/quote]That is why I made the second code suggestion.:cool:[/quote]yup - missed it! :P</description><pubDate>Thu, 12 Jun 2008 15:02:22 GMT</pubDate><dc:creator>Matt Miller (#4)</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]Lynn Pettis (6/12/2008)[/b][hr]Which track is right, the coding of the delete (I offered 2 solutions) or the fragmentation (disk and data)?[/quote]I was talking about the DELETE code... but, yes, I believe both tracks are correct and both need to be considered.  It may also be that someone made the log smaller and they got bit by unexpected growth during the delete.  That would certainly "Hang" the system until the growth completed and the delete completed.</description><pubDate>Thu, 12 Jun 2008 14:54:05 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]Matt Miller (6/12/2008)[/b][hr]Makes me wonder if it wouldn't be easier to just to the select...INTO on stuff you want to keep, blow out the original table and reinsert the items to keep.....I don't recall hearing how many rows would be left after this little adventure.....Either way - deleting that much in one chunk is bound to jam things up a bit.  Perhaps deleting in smaller chunks would help, too.[/quote]That is why I made the second code suggestion.:cool:</description><pubDate>Thu, 12 Jun 2008 14:52:55 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Makes me wonder if it wouldn't be easier to just to the select...INTO on stuff you want to keep, blow out the original table and reinsert the items to keep.....I don't recall hearing how many rows would be left after this little adventure.....Either way - deleting that much in one chunk is bound to jam things up a bit.  Perhaps deleting in smaller chunks would help, too.</description><pubDate>Thu, 12 Jun 2008 14:44:06 GMT</pubDate><dc:creator>Matt Miller (#4)</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]Jeff Moden (6/12/2008)[/b][hr][quote][b]Lynn Pettis (6/12/2008)[/b][hr][quote][b]Jeff Moden (6/12/2008)[/b][hr]Not sure the use of a correlated subquery (a form of hidden RBAR) will speed anything up here...  Maybe...The real fact of the matter is the OP says it used to work just fine... and doesn't now... what could be the problem?  Parallelism?[/quote]True enough Jeff.  Looking back at the original post (and paraphrasing), the system is hanging and the factory floor can't work.  The issue could be blocking.  Pretty sure that the NOLOCK hint is ignored on the delete, and if the DELETE is going to delete 11,000,000 rows, I wouldn't be surprised if SQL puts a table lock on the table.If it was working before but isn't now, the two things that come to my mind now would be data and disk fragmentation.  The OP should check these out.:cool:[/quote]Correct, WITH (NOLOCK) only affects SELECTs.I just can believe the delete of 11 million rows didn't get caught blocking before.  Somethings not quite right here.  I think Lynn is on the right track... I've seen it where the undocumented ability to DELETE alias has bitten folks before.  Gotta follow the rules and delete from a table name, instead.[/quote]Which track is right, the coding of the delete (I offered 2 solutions) or the fragmentation (disk and data)?:cool:</description><pubDate>Thu, 12 Jun 2008 14:35:07 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]Jeff Moden (6/12/2008)[/b][hr][quote][b]Lynn Pettis (6/12/2008)[/b][hr][quote][b]Jeff Moden (6/12/2008)[/b][hr]Not sure the use of a correlated subquery (a form of hidden RBAR) will speed anything up here...  Maybe...The real fact of the matter is the OP says it used to work just fine... and doesn't now... what could be the problem?  Parallelism?[/quote]True enough Jeff.  Looking back at the original post (and paraphrasing), the system is hanging and the factory floor can't work.  The issue could be blocking.  Pretty sure that the NOLOCK hint is ignored on the delete, and if the DELETE is going to delete 11,000,000 rows, I wouldn't be surprised if SQL puts a table lock on the table.If it was working before but isn't now, the two things that come to my mind now would be data and disk fragmentation.  The OP should check these out.:cool:[/quote]Correct, WITH (NOLOCK) only affects SELECTs.I just can believe the delete of 11 million rows didn't get caught blocking before.  Somethings not quite right here.  I think Lynn is on the right track... I've seen it where the undocumented ability to DELETE alias has bitten folks before.  Gotta follow the rules and delete from a table name, instead.[/quote]Sometimes there is no tracking in the amount of rows on tables and a sudden increase can be a "surprise" ;)</description><pubDate>Thu, 12 Jun 2008 14:30:06 GMT</pubDate><dc:creator>noeld</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]Lynn Pettis (6/12/2008)[/b][hr][quote][b]Jeff Moden (6/12/2008)[/b][hr]Not sure the use of a correlated subquery (a form of hidden RBAR) will speed anything up here...  Maybe...The real fact of the matter is the OP says it used to work just fine... and doesn't now... what could be the problem?  Parallelism?[/quote]True enough Jeff.  Looking back at the original post (and paraphrasing), the system is hanging and the factory floor can't work.  The issue could be blocking.  Pretty sure that the NOLOCK hint is ignored on the delete, and if the DELETE is going to delete 11,000,000 rows, I wouldn't be surprised if SQL puts a table lock on the table.If it was working before but isn't now, the two things that come to my mind now would be data and disk fragmentation.  The OP should check these out.:cool:[/quote]Correct, WITH (NOLOCK) only affects SELECTs.I just can believe the delete of 11 million rows didn't get caught blocking before.  Somethings not quite right here.  I think Lynn is on the right track... I've seen it where the undocumented ability to DELETE alias has bitten folks before.  Gotta follow the rules and delete from a table name, instead.</description><pubDate>Thu, 12 Jun 2008 14:14:17 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Could it be a case of your disks filling up with the transaction log?have you checked for free space?</description><pubDate>Thu, 12 Jun 2008 10:28:39 GMT</pubDate><dc:creator>steveb. </dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]Jeff Moden (6/12/2008)[/b][hr]Not sure the use of a correlated subquery (a form of hidden RBAR) will speed anything up here...  Maybe...The real fact of the matter is the OP says it used to work just fine... and doesn't now... what could be the problem?  Parallelism?[/quote]True enough Jeff.  Looking back at the original post (and paraphrasing), the system is hanging and the factory floor can't work.  The issue could be blocking.  Pretty sure that the NOLOCK hint is ignored on the delete, and if the DELETE is going to delete 11,000,000 rows, I wouldn't be surprised if SQL puts a table lock on the table.If it was working before but isn't now, the two things that come to my mind now would be data and disk fragmentation.  The OP should check these out.:cool:</description><pubDate>Thu, 12 Jun 2008 10:13:03 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Not sure the use of a correlated subquery (a form of hidden RBAR) will speed anything up here...  Maybe...The real fact of the matter is the OP says it used to work just fine... and doesn't now... what could be the problem?  Parallelism?</description><pubDate>Thu, 12 Jun 2008 08:37:11 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Try this...DELETE FROM tbItem l (nolock) Where exists(Select p.POID From tbProductionOrder p (nolock) where l.POID = p.POID AND PODescription LIKE '%00000%')</description><pubDate>Thu, 12 Jun 2008 05:05:48 GMT</pubDate><dc:creator>Sangeeta Satish Jadhav-362431</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Yes, please do.  I'd be interested in reading that if you find it.Thanks Lynn!</description><pubDate>Wed, 11 Jun 2008 15:10:46 GMT</pubDate><dc:creator>John Rowan</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]Matt Miller (6/11/2008)[/b][hr][quote][b]John Rowan (6/11/2008)[/b][hr]Also, your WHERE clause of PO.PODescription LIKE '%00000%' will normally produce a table scan.  It's a bit hard to say for sure though as you have not posted an execution plan or your index structure as requested by the other posters.[/quote]Agreed, although I can't think of how that wouldn't cause a table scan, thanks to the leading %.  That kind of forces a table scan (or a clustered index scan), since there's no decent way to use an index to seek those out.[/quote]I also agree, but we have to go with what the OP provided.  There is one thing, and unfortunately I don't have time to try and find it, I thought I had read in "Inside Microsoft SQL Server 2005 T-SQL Querying" that SQL Server 2005 had some improvements in its statitistics that improved query performance with leading wildcard characters in the LIKE clause.  When I have some free time (what ever that is) I will see if I can find it again.:cool:</description><pubDate>Wed, 11 Jun 2008 15:08:14 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]John Rowan (6/11/2008)[/b][hr]Also, your WHERE clause of PO.PODescription LIKE '%00000%' will normally produce a table scan.  It's a bit hard to say for sure though as you have not posted an execution plan or your index structure as requested by the other posters.[/quote]Agreed, although I can't think of how that wouldn't cause a table scan, thanks to the leading %.  That kind of forces a table scan (or a clustered index scan), since there's no decent way to use an index to seek those out.</description><pubDate>Wed, 11 Jun 2008 14:50:11 GMT</pubDate><dc:creator>Matt Miller (#4)</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Also, your WHERE clause of PO.PODescription LIKE '%00000%' will normally produce a table scan.  It's a bit hard to say for sure though as you have not posted an execution plan or your index structure as requested by the other posters.</description><pubDate>Wed, 11 Jun 2008 14:23:31 GMT</pubDate><dc:creator>John Rowan</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>I'd write it more like this:[code]DELETE FROM    dbo.tbItemFROM    dbo.tbItem I    INNER JOIN dbo.tbProductionOrder PO        ON (I.POID = PO.POID)WHERE    PO.PODescription LIKE '%00000%'[/code]You could also encolse this is a while loop and delete records in smaller batches.[code]declare @recordstodelete int,           @recordsdeleted int;set @recordstodelete = 5000;while (@recordsdeleted is null)       or (@recordsdeleted &amp;lt;&amp;gt; 0)begin -- while    DELETE TOP (@recordstodelete) FROM        dbo.tbItem    FROM        dbo.tbItem I        INNER JOIN dbo.tbProductionOrder PO             ON (I.POID = PO.POID)    WHERE        PO.PODescription LIKE '%00000%'    set @recordsdeleted = @@rowcount    -- BACKUP LOG ...  -- a transaction log backup could be coded here to manage t-log sizeend -- while[/code]:cool:</description><pubDate>Wed, 11 Jun 2008 13:42:18 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>It would be helpful if you mention the index structure on both the tables involved in delete operation.Manu</description><pubDate>Wed, 11 Jun 2008 13:23:50 GMT</pubDate><dc:creator>MANU-J.</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>The 11 Million is a standard number so it does not varyI also run DBCC DBREINDEX on the table earlierSo question of defragmentation should not come up</description><pubDate>Wed, 11 Jun 2008 07:31:18 GMT</pubDate><dc:creator>ibidapo22</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Fair enough, it was just that I seem to remember some reference to (nolock) dealing with potentially non-commited data and the obvious impacts of that might not be that desirable.Seems like we are both asking for more detail/history from the originator.Delete of 11 million rows doesn't sound like a daily task to me, but I might be wrong!!</description><pubDate>Wed, 11 Jun 2008 05:18:16 GMT</pubDate><dc:creator>UDBNT</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>[quote][b]UDBNT (6/11/2008)[/b][hr]Not sure on the validity of (nolock) on a table where you are deleting data?[/quote]The hint will be ignored. Deletes have to lock exclusivly, lock hints or no lock hints.</description><pubDate>Wed, 11 Jun 2008 05:06:15 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Index definitions?Has the total number of rows in the table changed since this worked properly?Are your indexes fragmented? Are the statistics out of date?I'm not asking just to be a pain. I'm asking because I want as clear a picture of the problem as possible.</description><pubDate>Wed, 11 Jun 2008 05:00:41 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>DELETE IFROM 	tbItem I (nolock) 	INNER JOIN tbProductionOrder PO (nolock) 	ON I.POID = PO.POID WHERE PODescription LIKE '%00000%'This will delete about 11000000 recordsOnce again this has been successfully severally</description><pubDate>Wed, 11 Jun 2008 03:15:16 GMT</pubDate><dc:creator>ibidapo22</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>Not sure on the validity of (nolock) on a table where you are deleting data?That aside, you mentioned this has worked in the past, but not so well now.What you don't state is other contributing factors like* Volume of data involve on both the related tables* Is there an RI link and has that any supportive indexing to help the query.* What sort of number of deletes are you expecting, ie When originally run a few rows to be deleted would not have the same impact as say several thousand.As with a lot of the forum items on this site (I know because I have asked questions as well), it works a lot better if you can give as much relevant details on the issue as possible.Cheers.</description><pubDate>Wed, 11 Jun 2008 03:06:39 GMT</pubDate><dc:creator>UDBNT</dc:creator></item><item><title>RE: Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>how many rows is that delete likely to affect? What indexes do you have on the 2 tables?</description><pubDate>Wed, 11 Jun 2008 02:56:39 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>Delete</title><link>http://www.sqlservercentral.com/Forums/Topic515014-146-1.aspx</link><description>I wrote query to delete some records in one of the table in my database. I set up job to run this query. The query is as below:DELETE IFROM 	tbItem I (nolock) 	INNER JOIN tbProductionOrder PO (nolock) 	ON I.POID = PO.POID WHERE PODescription LIKE '%00000%'This job has ran successfully in the past, but now it start hanging my system to extent that they cannot work in the factory, what are the possible causes?</description><pubDate>Wed, 11 Jun 2008 02:50:54 GMT</pubDate><dc:creator>ibidapo22</dc:creator></item></channel></rss>