sql - Delete cascade doesn't work in this scenario -
this question has answer here:
scenario: users can create relationship type, friends, , user can link other users relationship definition. if user deleted, relationship definitions should removed, , relationships between users need removed.
here demo database design on sql server: http://i.stack.imgur.com/3pcoy.png 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 goal when delete records table 1, delete related records in table 2 , table 3; when delete records table 2, delete related records in table 3.
and when try use "on delete cascade", there error "may cause cycles or multiple cascade paths", don't want use trigger.
do have suggestion on scenario? thanks,
isn't userid in table 3 redundant? or @ least if put userid in table 3 why have table 2? information in table 2 exists in table 3.
is there ever situation user id on table 3 not same relationship record on table 2? if not - table 2 redundant.
Comments
Post a Comment