エンティティとして仮定: HOMEWORK、STUDENT、ANSWER
および制約 (制約 1 をよく見てください):
1)A STUDENT can give only 1 ANSWER for the same HOMEWORK
2) A HOMEWORK can be solved by (0,N) STUDENT each giving their answer
3)AN ANSWER can be submitted by (0,N) STUDENT
4)(Obviously it is possible to give the same answer
for different HOMEWORK
and that different STUDENT can give the same answer for the same HOMEWORK)
例:
HOMEWORK STUDENT ANSWER
XXX A 1
XXX B 1
XXX C 2
YYY B 1
YYY C 1
ZZZ A 3
ZZZ C 1
注意 STUDENT が同じ宿題に対して 2 つの解答を提出することはあり得ません。したがって、行 XXX A 2 の挿入は許可されるべきではありません
これを三項関係でモデル化します。
STUDENT---------(0,N) <DO>(0,N)---------HOMEWORK
(0,N)
|
|
ANSWER
しかし、通常の変換アルゴリズムを使用してリレーショナル モデルに変換します。
-- -- means FOREIGN KEY
_____ means PRIMARY KEY
DO(HOMEWORK,STUDENT,ANSWER)
-- -- -- -- -- -- -- --
_______________________
HOMEWORK(with his attributes)
STUDENT(with his attributes)
ANSWER(with his attributes)
ANSWER は主キーの一部であるため、学生は同じ宿題を別の回答で解決できることを意味します。これは、必要な制約に違反しています。
おそらく私はこれを解決するでしょう:
1)-transforming the ternary relationship DO in a binary relationship and adding an attribute ANSWER to DO
-then create a trigger to check that the value of answer in DO is a possible answer.
Or
2)Keep ternary relationship but use another trigger
しかし、私はあなたの意見を知りたいです.(たとえば、ERでこの問題を別の方法でモデル化する場合)
PS - Postgres を使用しています