I have foreign keys set up for cascading deletes and it is taking about 30 minutes for a delete command to run. Here is a simplified view of that I am deleting with a row count:
DELETE from Directories WHERE Type = 1
Structure:
Directory table: (1.2K rows returned from WHERE clause)
+—+ File table with DirectoryID foreign key (50K rows)
+————-+ Tag table with FileID foreign key (28K rows)
This is taking 28 minutes to run.
Should I avoid using cascading deletes with many tiers or is there something simple I can do to improve performance? Without foreign keys, I can delete 50K+ rows in less than a second.
I’m new to both SQL and SQL Server Compact Edition 3.5. All of the primary keys are indexed. I’ve added indexes on the foreign keys which did not help. Any help would be appreciated.
According to this discussion, if you have composite indexes on your foreign keys you might want to look into having simple indexes that include only the foreign key field.