在 ERD 中获得正确的主键和外键
我读了我的笔记,现在我不确定密钥。
我的逻辑图
alt text http:// files.getdropbox.com/u/175564/db/db-11.png
该表应符合以下物理 ERD
alt text http://files.getdropbox.com/u/175564/db/db-22.png
我只有一个外键表问题
。
我想知道
- 表中的
question-id
和question-tag
Question-tag-xref 以及question-表 Answers 中的 id
和answer
也是外键吗?
I read my notes and I am now unsure about the keys.
My logical diagram
alt text http://files.getdropbox.com/u/175564/db/db-11.png
This table should be in line with the following physical ERD
alt text http://files.getdropbox.com/u/175564/db/db-22.png
I have only one foreign key in the table Question
.
I would like to know
- should the
question-id
andquestion-tag
in the table Question-tag-xref, ANDquestion-id
andanswer
in the table Answers be also foreign keys?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Masi - 逻辑模型通常不包含数据类型(字符串、整数等)信息,但指示属性(成为物理模型中的列)是否是可选的(可以为 null 或不是 null)。
也就是说,是的 - QUESTION-ID 和 QUESTION-TAG 列将是 QUESTION-TAG-XREF 表中的外键。 以下是 QUESTION-TAG-XREF 的物理视图:
QUESTION-TAGS-XREF
两列都是 pk,以确保给定问题不能有重复的标签。
您是正确的,QUESTION-ID 将是 ANSWERS 表中引用 QUESTION 表的外键。
Masi - Logical models don't usually contain data type (string, int, etc) information, but do indicate if the attribute (becomes a column in the Physical model) is optional (able to be null or not).
That said, yes - the QUESTION-ID and QUESTION-TAG columns would be foreign keys in the QUESTION-TAG-XREF table. Here's a physical view of QUESTION-TAG-XREF:
QUESTION-TAGS-XREF
Both columns are the pk to ensure you can't have duplicate tags for a given question.
You are correct that QUESTION-ID would be a foreign key in the ANSWERS table, in reference to the QUESTION table.
查看两个 ERD,这是我想要的外键
落实到位:
第一个 ERD:
Question-Tag-xref(question-id) 应引用 Question(question-id)。
答案(question-id)应引用问题(question-id)。
Question(user-id) 应该引用 User(user-id)。
第二个 ERD:
Question-Tag-xref(question-id) 应引用 Question(question-id)。
答案(question-id)应引用问题(question-id)。
问题(user-id)应参考用户信息(user-id)。
我在问题表中也只有一个外键。
回答你的问题:
Question-tag-xref 中的列 Question-id 应具有对 Question(question-id) 的外键引用。
答案表中的列 Question-id 应具有对 Question(question-id)
K的外键引用
Looking at both ERDs, here are the foreign keys I would want to
put in place:
First ERD:
Question-Tag-xref(question-id) should refer to Question(question-id).
Answers(question-id) should refer to Question(question-id).
Question(user-id) should refer to User(user-id).
Second ERD:
Question-Tag-xref(question-id) should refer to Question(question-id).
Answers(question-id) should refer to Question(question-id).
Question(user-id) should refer to user-info(user-id).
I get only one foreign key in the Question table too.
In answer to your question:
The column question-id in Question-tag-xref should have a foreign key reference to Question(question-id).
The column question-id in the answers table should have a foreign key reference to Question(question-id)
K