Scenario: Users can create a relationship type, like Friends, and then the user can link some other users as the relationship definition. if the user deleted, relationship definitions should be removed, and the relationships between users also need removed.
here is a demo database design on sql server: https://i.stack.imgur.com/3pcOy.png the foreign keys are:
- Table 2.UserId reference Table 1.UserId;
- Table 3.RelationShipId reference Table 2.RelationshipId;
- Table 3.UserId reference Table 1.UserId;
- Table 3.OtherUserId reference Table 1.UserId;
and my goal is when delete records from table 1, it will delete related records in table 2 and table 3; when delete records from table 2, it will delete related records in table 3.
and when i try to use "ON DELETE CASCADE", there is an error "may cause cycles or multiple cascade paths", also i don't want to use trigger.
do you have suggestion on this scenario? Thanks,