在Apache Derby中,外键是否会自动填充列?

huangapple go评论73阅读模式
英文:

Do foreign keys in apache derby automatically populate a column?

问题

<br/>
最近我一直在尝试创建关系数据库(RDB),我遇到的问题是,具有外键约束的列不会填充引用列的值(它们将具有空值)。我唯一成功的方式是手动填充它们,这样才会有正确的值。<br/>
不过,我要说的是,这些外键确实阻止我在这两列中使用不同的值。<br/>
简而言之/结论:<br/>
那么,外键只是约束列中的值,而不一定会填充该列吗?<br/>
如果是这样,有什么函数/方法可以实现这个目标吗?<br/>
谢谢,<br/>
Michael

英文:

<br/>
Recently I've been trying to create a RDB, and the problem I'm running into is that the columns I have with a foreign key constraint will not populate with the values of the referenced column (it will have null values). The only way I've managed to have the correct values is to populate it manually.<br/>
I will say, however, that the foreign keys did stop me from having different values in the two columns. <br/>
TLDR/Conclusion:<br/>
So, do foreign keys simply constrain the values in a column without necessarily populating that column? <br/>
If so, what would be a function/method that would achieve this goal? <br/>
Thanks, <br/>
Michael

答案1

得分: 1

外键约束只是约束列中的值,而不填充该列。

您的应用程序应将引用表中的外键列的值设置为所指表中引用列的值。

通常,行之间存在关系,您的应用程序知道它正在处理与另一张表中的引用行特定关系的特定行。

例如,在简单的员工管理应用程序中,您可能会有 EMPLOYEEDEPARTMENT 表,您的 EMPLOYEE 表可能具有外键列 MANAGER_NAMEDEPARTMENT_NAME。在为新员工插入新行时,您的数据录入表单已经要求操作员从部门列表中选择员工的部门,并从经理列表中选择员工的经理,因此在执行 INSERT 时,您的应用程序会使用该数据设置 MANAGER_NAMEDEPARTMENT_NAME

英文:

Foreign key constraints simply constrain the values in a column without populating that column.

Your application is expected to set the value of the foreign key column in the referring table to the value of the referenced column in the referenced table.

Typically, the rows are related, and your application knows that it is working with a particular row that is in a particular relationship to the referenced row in the other table.

For example, in a simple workforce management application, you might have tables EMPLOYEE, and DEPARTMENT, and your EMPLOYEE table might have foreign key columns MANAGER_NAME and DEPARTMENT_NAME. When inserting a new row for a new employee, your data entry form has already asked the operator to pick the employee's department from a list of departments, and the employee's Manager from a list of managers, and so your application then sets the MANAGER_NAME and DEPARTMENT_NAME with that data at the time you perform your INSERT

huangapple
  • 本文由 发表于 2020年9月22日 16:59:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/64006374.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定