Vendor
(PK) - Id
Stand
(PK) - Id
Item
(PK) - Id
UnavailableItem
(PK) - ItemId - (fk - cascaded delete if Item is deleted)
The database above represents an athletic stadium.
Problem:
I can create everything just fine until I add the last Foreign Key listed (FK_UnavailableItem_StandId_Stand_Id) with a Delete Rule: CascadedSQL Compact 3.5 (using VS 2010 Server Explorer) reports the following error: The referential relationship will result in a cyclical reference that is not allowed.
I understand that if I have an record in the UnavailableItem table, and its Vendor gets deleted, it will try to be deleted twice:
However, this does not appear to be cyclical to me. The cascading-deletes branch into two paths (Deleted Stands and Deleted Items) that both end in a the same record being deleted... but it ends there. There is no infinite loop of cascading-deletes after that. Am I missing something, or is this a limitation of the tools I am using?
Thank you for any help you can provide!
You can't cascade delete through two branches, it is a limitation of the tool. But cascade delete is generally a bad thing to do to your poor innocent database anyway. Delete from the bottom table and move up. That way if you have 100000000000 records at the bottom you can do them in batches for performance. Cascade delete can cause performance problems.
Assuming SSCE does not allow cascade delete along two paths, you could remove the cascade delete for UnavailableItem.StandId.
At least, it will still cascade when a Vendor, or an Item is deleted.
And if UnavailableItem still contains rows for deleted Stands, at least they could be filtered out when joining UnavailableItem with Stand, when building refilling orders...
精彩评论