sql server - Delete statement in SQL is very slow -


i have statements timing out:

delete [table] [col] in ( '1', '2', '6', '12', '24', '7', '3', '5') 

i tried doing 1 @ time this:

delete [table] [col] in ( '1' ) 

and far it's @ 22 minutes , still going.

the table has 260,000 rows in , 4 columns.

does have ideas why slow , how speed up? have non-unique, non-clustered index on [col] i'm doing on. i'm using sql server 2008 r2

update: have no triggers on table.

things can cause delete slow:

  • deleting lot of records
  • many indexes
  • missing indexes on foreign keys in child tables. (thank @cesaralvaradodiaz mentioning in comments)
  • deadlocks , blocking
  • triggers
  • cascade delete (those ten parent records deleting mean millions of child records getting deleted)
  • transaction log needing grow
  • many foreign keys check

so choices find out blocking , fix or run deletes in off hours when won't interfering normal production load. can run delete in batches (useful if have triggers, cascade delete, or large number of records). can drop , recreate indexes (best if can in off hours too).


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -