Many-to-many relationships ERD

风格不统一 提交于 2019-12-24 14:07:31

问题


I'm currently designing a database design for a thesis repository. I came across this situation:

• A student can submit ONLY ONE thesis, and a thesis can be submitted by MANY students.

However, I do not want to make the Thesis ID repeat for the Thesis table. Should I use a junction table? I have made an initial design (below) with one. Am I in the right track?


回答1:


You are almost there. Only I have a comment on the Thesis_Students table, I see you have both ThesisID and StudentID as PK, which will cover that, one student should be related to a Thesis only once. But you have an additional condition "A student can submit ONLY ONE thesis". So you need an additional UNIQUE constraint with only StudentID, so that no more than one entry for any StudentID can be inserted. (Well actually, in which case your PK for ThesisID + StudentID not needed anymore, since you cannot anyhow insert more than one entry for the StudentID).




回答2:


I suggest that just put thesisID column on Students Table,



来源:https://stackoverflow.com/questions/34215414/many-to-many-relationships-erd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!