I have a table structure similar to:
Portfolios
Properties
Units
Leases
All tables are setup with foreign key relationships and cascade deletes. I want to be able to delete a portfolio, which would in turn delete all properties assigned to that portfolio, all units assigned to those properties, and all leases assigned to those units.
I'm getting errors similar to:
The DELETE statement conflicted with the REFERENCE constraint "FK_Leases_Units". The conflict occurred in database "MyDb", table "Leases", column 'UnitId'.
What is the proper way to delete a "tree" of data like this?
If it matters, I'm using MS SQL Server 2008.