tags:

views:

42

answers:

2

I've a table in sql server 2005 with a chaild table that has millions of records in it. Whenever I issue a delete command even with a where clause, it takes abnormally long to execute it. Is it bacause the size of the child table that is causing this delay? What are the ways to make the delete query faster?

thanks, sweta.

+3  A: 

The usual suspects:

  • Trigger?
  • Index on column(s) in the WHERE clause?
  • Index on FL column(s) in child table FK column?
  • Cascade delete etc: see index points

Also:

  • log file growing?
  • ...

Edit, after comments: You need indexes...

gbn
Triggers - noneIndex on column(s) in the WHERE clause - noneCascade delete - noneThis is the delete command..delete from sal_process_details where sal_process_master_id in (select sal_process_master_id from sal_process_master WHERE Process_month = @month and process_year = @year and employee_id in(select employee_id from sal_process_temp_emp))
sweta Jha
+2  A: 

It sounds like it may be doing a table scan on the child table. Make sure that the joining column has an index on the child table.

Adam Ruth
Is there a way i can temporarily suspend the foreign key constraint between the two tables and enable the constraint after deletion is complete. pls let me know if there is some other work around to this problem.
sweta Jha
http://stackoverflow.com/questions/159038/can-foreign-key-constraints-be-temporarily-disabled-using-tsql
Adam Ruth