関係データベースにおける外部キーに関する記述のうち, 適切なものはどれか。
平成29年度 秋期 ITパスポート試験 問88
This question's explanation and your answers so far.
問 88
Incorrectア
The property a foreign key has is referential integrity (the referential constraint): only values that already exist in the referenced primary key may be entered. The uniqueness constraint forbids duplicate values and is a property of the primary key, not of the foreign key. The two terms have been matched the wrong way around.
Incorrectイ
Not allowing duplicate values is a property of the primary key. With a foreign key, multiple rows may reference the same value in the referenced table, so the same value commonly appears more than once (for example, the same customer ID appearing in several order rows). Therefore the statement that duplicate values are forbidden is incorrect.
- ウ
正解 A foreign key is a column that links one table to another by referencing the primary key (or a unique column) of another table. One table may reference several other tables, and a foreign key can be defined for each such reference. For example, if an “Order” table references both a “Customer” table and a “Product” table, two foreign keys, the customer ID and the product ID, can be set on the same table. Therefore choice “ウ”, which states that multiple foreign keys can be set on a single table, is appropriate.
Incorrectエ
When the referenced primary key is a composite key made up of several fields, several fields can correspondingly be grouped together and set as a single foreign key (a composite foreign key). Therefore the statement that they cannot be grouped together is incorrect.
- A foreign key is a column that references another table's primary key to relate tables; its property is referential integrity. Duplicate values are allowed, multiple foreign keys can be set on one table, and several fields can be combined into a composite foreign key.
- The uniqueness constraint and the no-duplicates rule are properties of the primary key; do not confuse them with the properties of the foreign key.