开发者

SQL - Multiple one-to-many relationships

Is it possible somehow to do multiple one-to-many relationships between 2 tables? Like:

Table abc

  • abcID
  • defID
  • message

Table def

  • defID
  • abcID
  • message

If yes how c开发者_Python百科an I then make a new abc entry with the entity framework?


You only need a single Many-Many relationship. Simply move QuestionId out of the quiz_answers table and move AnswerId out of the quiz_questions table:

Create Table quiz_questions
(
QuestionId ... Not Null Primary Key
, Question ...
, ...
)

Create Table quiz_answers
(
AnswerId ... Not Null Primary Key
, Answer ...
, ...
)

Create Table quiz_question_answers
(
QuestionId ... Not Null References quiz_questions ( QuestionId )
, AnswerId ... Not Null References quiz_answers ( AnswerId )
, Constraint PK_quiz_question_answers Primary Key ( QuestionId, AnswerId )
)


Yes, it is a one-to-one join from abc to def and then another from def back to abc; so abc joins to def on defID and def joins to abc on abcID.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜