Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

postgresql - Can my ERD have a triangular relationship between 3 entities?

Project --- Skill --- Employee

A project requires many skills. A skill can be required for many projects.

An employee can have many skills. A skill can be 'had' by many employees.

Is this information enough in order to deduct which employees are in which projects? Or should there be another relationship between Projects and Employees?

Like this: A project can have many employees. An employee can be a part of many projects.

So it would basically become a triangle of these 3 entities, with weak entities in-between? Or is there a better solution?

question from:https://stackoverflow.com/questions/65841591/can-my-erd-have-a-triangular-relationship-between-3-entities

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ERDs are great if you already grok how to automatically verbalize diagrams. When in doubt use plain text: predicates, constraints, relations. Better and more powerful than ERDs.

-- Project PRO exists.
--
project {PRO}
     PK {PRO}
-- Employee EMP exists.
--
employee {EMP}
      PK {EMP}
-- Skill SKL exists.
--
skill {SKL}
   PK {SKL}
-- Employee EMP has skill SKL.
--
emp_skl {EMP, SKL}
     PK {EMP, SKL}

FK1 {EMP} REFERENCES employee {EMP}
FK2 {SKL} REFERENCES skill    {SKL}
-- Project PRO requires skill SKL.
--
pro_skl {PRO, SKL}
     PK {PRO, SKL}

FK1 {PRO} REFERENCES project {PRO}
FK2 {SKL} REFERENCES skill   {SKL}
-- Employee EMP with skill SKL, is assigned
-- to project PRO, that requires that skill.
--
emp_pro {EMP, PRO, SKL}
     PK {EMP, PRO}

FK1 {EMP, SKL} REFERENCES emp_skl {EMP, SKL}
FK2 {PRO, SKL} REFERENCES pro_skl {PRO, SKL}

Note:

All attributes (columns) NOT NULL

PK = Primary Key
FK = Foreign Key

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...