関係データベースの主キーに関する記述のうち, 適切なものはどれか。
平成26年度 春期 ITパスポート試験 問64
This question's explanation and your answers so far.
問 64
Incorrectア
The role of relating (linking) one table to another is played by the foreign key, which references the primary key of another table. A primary key is a column that uniquely identifies rows within its own table; the relationship itself is established by the reference from a foreign key to a primary key. In practice, tables can also be joined on columns other than the primary key, so the restriction that tables are related only through the primary key does not hold.
Incorrectイ
A primary key carries a uniqueness constraint, so the same value must not exist in more than one row. If duplicates were allowed, specifying that value would not narrow the result down to a single row, and the primary key would fail in its purpose of identifying a row uniquely. Duplicate values are allowed in ordinary columns that are not primary keys (and in foreign key columns).
- ウ
正解 A primary key is a column (or a combination of columns) used to distinguish one row (record) in a table from all the others and identify it uniquely. In order to tell rows apart reliably, a primary key is subject to two constraints: (1) uniqueness — the same value must not appear in two or more rows; (2) not NULL (entity integrity) — the value must not be empty (NULL = the value does not exist or is unknown). Since NULL represents the state in which the value is unknown, a primary key that is NULL loses the clue needed to identify that row, so the primary key can no longer serve its original purpose. Therefore ウ, which states that the primary key value cannot be NULL, is appropriate.
Incorrectエ
When a single column cannot identify a row uniquely, several columns can be combined to form the primary key. This is called a composite key (composite primary key); for example, a combination such as order number plus line item number secures uniqueness. Therefore the statement that multiple columns cannot be combined to form a primary key is wrong.
- The two major constraints on a primary key — uniqueness (the same value cannot be duplicated) and not NULL (no empty value). Satisfying both is what makes it possible to pin down a single row in the table.
- The division of roles between primary key and foreign key — the primary key uniquely identifies rows within its own table, while relating tables to each other is handled by a foreign key that references another table's primary key. Also, when one column is not enough, multiple columns can be bundled into a composite key.