在 ERD 中获得正确的主键和外键

发布于 2024-07-29 16:36:31 字数 629 浏览 2 评论 0原文

我读了我的笔记,现在我不确定密钥。

我的逻辑图

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-idquestion-tag Question-tag-xref 以及 question-表 Answers 中的 idanswer 也是外键吗?

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 and question-tag in the table Question-tag-xref, AND question-id and answer in the table Answers be also foreign keys?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁人与我共长歌 2024-08-05 16:36:31

Masi - 逻辑模型通常不包含数据类型(字符串、整数等)信息,但指示属性(成为物理模型中的列)是否是可选的(可以为 null 或不是 null)。

也就是说,是的 - QUESTION-ID 和 QUESTION-TAG 列将是 QUESTION-TAG-XREF 表中的外键。 以下是 QUESTION-TAG-XREF 的物理视图:

QUESTION-TAGS-XREF

  • QUESTION-ID(与 QUESTIONS 表的 pk、fk 关系)
  • QUESTION-TAG-CODE(与 QUESTION-TAG 表的 pk、fk 关系) )

两列都是 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

  • QUESTION-ID (pk, fk relationship with QUESTIONS table)
  • QUESTION-TAG-CODE (pk, fk relationship with QUESTION-TAG table)

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.

仙女 2024-08-05 16:36:31

查看两个 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文