Oracle约束官方文档--外键约束

Foreign Key Constraints

      Whenever two tables contain one or more common columns, Oracle Database can enforce the relationship between the two tables through a foreign key constraint, also called a referential integrity constraint. The constraint requires that for each value in the column on which the constraint is defined, the value in the other specified other table and column must match. An example of a referential integrity rule is an employee can work for only an existing department.
只要两张表包含一个或多个公共的列,Oracle数据库都可以通过外键约束(也叫引用完整性约束)来强制两个表的关系。约束要求,在定义约束的列中的每个值,在另一个指定的表和列中必须有相对应的值(子表A键引用父表B键,在子表A键建立外键约束。子表A列中的每个值,父表B键都要有相应的值)。一个关于描述引用约束规则的例子:员工只能为现有部门工作(即员工与部门间的关系)。
Table 5-2 lists terms associated with referential integrity constraints.

下表列出了与引用完整性约束相关的术语。

Term Definition

Foreign key

The column or set of columns included in the definition of the constraint that reference a referenced key. For example, the department_id column in employees is a foreign key that references the department_id column in departments.

Foreign keys may be defined as multiple columns. However, a composite foreign key must reference a composite primary or unique key with the same number of columns and the same data types.

The value of foreign keys can match either the referenced primary or unique key value, or be null. If any column of a composite foreign key is null, then the non-null portions of the key do not have to match any corresponding portion of a parent key.

Referenced key

The unique key or primary key of the table referenced by a foreign key. For example, the department_id column in departments is the referenced key for the department_id column in employees.

Dependent or child table

The table that includes the foreign key. This table is dependent on the values present in the referenced unique or primary key. For example, the employees table is a child of departments.

Referenced or parent table

The table that is referenced by the foreign key of the child table. It is this table's referenced key that determines whether specific inserts or updates are allowed in the child table. For example, the departmentstable is a parent of employees.

外键:

引用 被引用键的  单列或列集(键:代表列。外键:引用其他表.列的列,即子表中的列)。

例如,employees员工表的department_id部门编号列是外键,其引用departments部门表的department_id部门编号列。

外键可以被定义为多列。无论如何,一个多列组成的外键,必须引用一个多列组成的主键或唯一键,主键或唯一键的列个数及数据类型要与外键一致。
外键的值可以与引用的主键或唯一键的值相匹配,也可以与null匹配。如果组成外键的列中有一列为null,则外键非null的部分不必和父键的任何相应部门相匹配。(如果复合外键的任何列为空,则该键的非空部分不必与父键的任何相应部分匹配。)

引用的键/列

表中的唯一键或主键被一个外键引用。比如departments表的department_id列,是employees表department_id列的引用键。(被引用键,父表的主键或唯一键)

从属表或子表/依赖表

包含外键的表。这个表依赖于引用的主键或唯一键中的值。例如,employees表是departments表的子表

引用的表或父表

被子表中外键引用的表。这个表的引用键决定是否允许子表中INSERT或UPDATE操作。例如,departments表时employees表的父表。

Figure 5-1 shows a foreign key on the employees.department_id column. It guarantees that every value in this column must match a value in the departments.department_id column. Thus, no erroneous department numbers can exist in the employees.department_id column.

Figure 5-1 Referential Integrity Constraints

发布了57 篇原创文章 · 获赞 20 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/shafatutu/article/details/96819722