Reputation: 320
We have a entity users
with attributes id
, name
. How to 'implement' the relationship between these users with rules:
lover
, married
, engaged
with
another userJack Anne
, Anne Jack
)this is solely made up, just me learning db
So I made this ER diagram, the blue lines is what I set to unique/alternate-key
users_relationship
with
users.name
, rel_type.type
.Thanks, any tips/suggestions are welcome!
Upvotes: 1
Views: 95
Reputation: 48770
Yes, it's a good approach, and is at least 3NF.
To avoid symmetric duplicates, add an extra constraint in the table users_relationship
, as in:
create table users_relationship (
column1 definition,
column2 definition,
...
contraint uq_pair check (users_id < users_2_id)
...
);
Yes, it looks fine.
Upvotes: 1