Home > Alagad > Sproc to Cascade Deletes In SQL Server

Sproc to Cascade Deletes In SQL Server

February 27th, 2009

As a developer, from time to time you need to delete an record out of a database. And, if that record has a number of tables that refer to it by foreign key (and heaven forbid those tables are themselves referenced), deleting a single row can be quite a headache. This wouldn’t be so bad if your foreign keys were set to cascade deletes, but they rarely are. In these cases you’re pretty much stuck writing a lot of SQL to delete one single record. For situations like this I’ve created a stored procedure which will automatically cascade delete records for you. Here’s the complete sproc:

Source:Sproc to Cascade Deletes In SQL Server

admin Alagad