views:

1237

answers:

2

I have a table containing hundreds of entries and I am trying to delete a small range. It is taking a long time, in fact it is not being executed.

I monitored the query from the activity monitor and its status is "Suspended"

Is there anyone knows what may cause this problem?

+1  A: 

What's the SQL you're running? Any triggers on the table, or any cascaded deletes to tables that have triggers on? Anything in the "Blocked By" column or Wait Type?

Try executing the following in management studio (on the database in question):

dbcc checkdb
dbcc checkcatalog
Steven Robbins
David Bonnici
Sorry, I meant the SQL statement :-)
Steven Robbins
delete from tbl_obejcts where objectname < 450 - (Only 450 Records)
David Bonnici
Blocked by = 0 and Wait Type = PAGIOLATCH_SH
David Bonnici
What about the Blocked By and Wait Type columns in activity monitor? Usually things only go suspended if they are waiting for I/O or there is an explicit wait clause in the SQL.
Steven Robbins
It's waiting for I/O then, sounds like you might have a corrupted database or something wierd going on with the I/O on the machine. Try running:dbcc checkdbdbcc checkcatalog
Steven Robbins
What are these queries? dbcc checkdb dbcc checkcatalog Thanks
David Bonnici
If you run them they will check the database and catalog and report any errors found. If this gives you nothing then the next step is probably Perfmon to monitor the disk queue lengths, but that's a systems issue rather than a SQL one really.
Steven Robbins
A: 

Depending on the size of your database and the number of constraints that have to be checked when deleting a row, deletes can take a very, very long time. I never delete more than one row at a time from my databases. It's just too resource-intensive on the system. This is one of the few places where a cursor, or an iteration in non-database code (C#, Java, whatever) can beat a set-based query. I even put a small delay of a few milliseconds between deletes to make sure nothing gets locked up for too long. You can bring a database to its knees by deleting a range of data from a table.

Eric Z Beard