在ERD中获取主键和外键

时间:2022-07-16 11:29:46

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

alt text http://files.getdropbox.com/u/175564/db/db-11.png

This table should be in line with the following physical ERD

该表应符合以下物理ERD

alt text http://files.getdropbox.com/u/175564/db/db-22.png

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?
  • 如果表格中的问题ID和问题标签问号标签xref,表格中的问题ID和答案也是外键吗?

2 个解决方案

#1


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).

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

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-ID和QUESTION-TAG列将是QUESTION-TAG-XREF表中的外键。这是QUESTION-TAG-XREF的物理视图:

QUESTION-TAGS-XREF

  • QUESTION-ID (pk, fk relationship with QUESTIONS table)
  • QUESTION-ID(与QUESTIONS表的pk,fk关系)

  • QUESTION-TAG-CODE (pk, fk relationship with QUESTION-TAG table)
  • QUESTION-TAG-CODE(pk,fk与QUESTION-TAG表的关系)

Both columns are the pk to ensure you can't have duplicate tags for a given question.

两列都是pk,以确保您不能为给定问题提供重复标记。

You are correct that QUESTION-ID would be a foreign key in the ANSWERS table, in reference to the QUESTION table.

你是正确的,QUESTION-ID将是ANSWERS表中的外键,参考QUESTION表。

#2


Looking at both ERDs, here are the foreign keys I would want to put in place:

看看这两个ERD,这里是我想要放置的外键:

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).

第一个ERD:Question-Tag-xref(question-id)应该引用Question(question-id)。答案(问题ID)应该引用问题(问题ID)。问题(user-id)应该引用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).

第二个ERD:Question-Tag-xref(question-id)应该引用Question(question-id)。答案(问题ID)应该引用问题(问题ID)。问题(user-id)应该引用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)

回答你的问题:Question-tag-xref中的列question-id应该有一个对Question(question-id)的外键引用。 answers表中的列question-id应该有一个对Question的外键引用(question-id)

K

#1


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).

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

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-ID和QUESTION-TAG列将是QUESTION-TAG-XREF表中的外键。这是QUESTION-TAG-XREF的物理视图:

QUESTION-TAGS-XREF

  • QUESTION-ID (pk, fk relationship with QUESTIONS table)
  • QUESTION-ID(与QUESTIONS表的pk,fk关系)

  • QUESTION-TAG-CODE (pk, fk relationship with QUESTION-TAG table)
  • QUESTION-TAG-CODE(pk,fk与QUESTION-TAG表的关系)

Both columns are the pk to ensure you can't have duplicate tags for a given question.

两列都是pk,以确保您不能为给定问题提供重复标记。

You are correct that QUESTION-ID would be a foreign key in the ANSWERS table, in reference to the QUESTION table.

你是正确的,QUESTION-ID将是ANSWERS表中的外键,参考QUESTION表。

#2


Looking at both ERDs, here are the foreign keys I would want to put in place:

看看这两个ERD,这里是我想要放置的外键:

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).

第一个ERD:Question-Tag-xref(question-id)应该引用Question(question-id)。答案(问题ID)应该引用问题(问题ID)。问题(user-id)应该引用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).

第二个ERD:Question-Tag-xref(question-id)应该引用Question(question-id)。答案(问题ID)应该引用问题(问题ID)。问题(user-id)应该引用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)

回答你的问题:Question-tag-xref中的列question-id应该有一个对Question(question-id)的外键引用。 answers表中的列question-id应该有一个对Question的外键引用(question-id)

K