sql - Delete cascade doesn't work in this scenario -


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:

  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 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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -