0

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:

  1. Table 2.UserId reference Table 1.UserId;
  2. Table 3.RelationShipId reference Table 2.RelationshipId;
  3. Table 3.UserId reference Table 1.UserId;
  4. 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,

FireFish
  • 1
  • 1

1 Answers1

0

Isn't the userid in table 3 redundant? Or at least if you put the userid in table 3 why have table 2? The information in table 2 already exists in table 3.

Is there ever a situation where the user id on table 3 would not be the same as the relationship record on table 2? If not - table 2 is redundant.

Jeff B
  • 535
  • 1
  • 6
  • 15