Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Issue setting Foreign key constraint
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01518536
Message ID:
01518946
Views:
35
>>>>Hi,
>>>>
>>>>When creating a FOREIGN KEY constraint in SSMS I get message that:
>>>>
>>>>….  may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, 
>>>>or modify other FOREIGN KEY constraints.
>>>>
>>>>
>>>>If I understand correctly the problem is that the table where I am attempting to set a Foreign key constraint has a dependency on some other table that creates a conflict. My tables have many links. So my question is, how can I find out which table has a link to this table that I need to change? How do I find out?
>>>>Thank you for any other suggestions.
>>>
>>>This is crazy. I find that two foreign keys in a table, seemingly absolutely not related, cause the problem. I have to add NO ACTION on delete and update to one or the other. But I don't see why.
>>
>>You will probably find that the two tables referenced by the FKs *are related*. Simple case:
>>TableC has FKs to TableA and TableB both with cascading deletes.
>>TableB has FK to TableA. If you now attempt to set cascading deletes in this you will get the error since there are two paths by which TableC rows can be deleted - directly by a TableA deletion and also indirectly following the cascaded deletion of rows in TableB
>>
>>But I don't know a simple way to track down the problem when the paths are not so obvious.....
>
>What you describe (simple case) is pretty much what I have. And I have read about this in some other forums. But what I can't understand is the "paths by which TableC rows can be deleted". That is, what defines the "path" by which rows are updated/deleted? I thought that the case should be simple. When user deletes a record in TableA (or whichever table where there is a unique field) all tables where this unique field have FK constraint should be set to NULL. Pretty simple it seems. But SQL Server must work more complicated than I think.
>What I have (and you describe) seems to be a fairly common case of a database application. How do others resolve this?

When the record is deleted in the Parent table and you specified CASCADE delete, all related records in the child table are deleted. If you somehow have cyclic relations it makes the above impossible.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform