how to represent symmetric many to many relationship

后端 未结 5 930
盖世英雄少女心
盖世英雄少女心 2020-12-06 18:05

suppose i have a entity called USER and a relationship FRIENDSHIP exist between two USERs SO for that i have a table \'USER\' and a relationship table \'FRIENDSHIP\'

5条回答
  •  春和景丽
    2020-12-06 18:57

    If you store the two rows, you will be required to enforce an integrity rule that ensures that friendships always come in pairs.

    Store only one row in the table (say, FR), and create a view SYMFR as

    SELECT x,y FROM FR UNION SELECT x as y, y as x FROM FR

提交回复
热议问题