-- Group GRP exists.
--
group {GRP}
PK {GRP}
-- Room ROM exists.
--
room {ROM}
PK {ROM}
- Each room belongs to at most one group;
each group may own more than one room.
-- Room ROM is owned by group GRP.
--
room_group {ROM, GRP}
PK {ROM}
SK {ROM, GRP}
FK1 {ROM} REFERENCES room {ROM}
FK2 {GRP} REFERENCES group {GRP}
Each group has at most one main room;
each main room belongs to exactly one group.
If a room is a main room for a group,
then that room must belong to that group.
-- Room ROM is main room for group GRP.
--
main_room {GRP, ROM}
PK {GRP}
AK {ROM}
FK {ROM, GRP} REFERENCES
room_group {ROM, GRP}
Notes:
Note that having a main room is not mandatory in the model, use application level to enforce it.
All attributes (columns) NOT NULL
PK = Primary Key
AK = Alternate Key (Unique)
SK = Proper Superkey (Unique)
FK = Foreign Key
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…