Many-to-many relationships ERD

2019-08-10 13:58发布

问题:

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,