DELETE performance in SQL Server on clustered index, large table

Erik Sundström picture Erik Sundström · Jun 20, 2011 · Viewed 14.6k times · Source

I have a table with more than 20 million rows, and when i do:

DELETE [Table] WHERE ID = ?

It takes over 40 seconds. The ID column is clustered.

Is this what you could expect? or is it possible to optimize this?

Answer

Damien_The_Unbeliever picture Damien_The_Unbeliever · Jun 20, 2011

In addition to the fine points JNK included in their answer, one particular killer I've seen is when you're deleting rows from the referenced table for one or more foreign key constraints, and the referencing column(s) in the referencing table(s) aren't indexed - you're forcing a table scan on each of those tables to occur before the delete can be accepted.