Many-to-many relationships ERD

2019-08-10 13:55发布

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?

enter image description here

2条回答
老娘就宠你
2楼-- · 2019-08-10 14:48

I suggest that just put thesisID column on Students Table,

查看更多
Deceive 欺骗
3楼-- · 2019-08-10 14:54

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).

查看更多
登录 后发表回答