関係データベースの表に設定する主キー, 外部キー及びインデックスのうち, 一つの表に対して複数設定できるものだけを全て挙げたものはどれか。
平成25年度 秋期 ITパスポート試験 問51
This question's explanation and your answers so far.
問 51
Incorrectア
It is true that indexes can be set multiple times, but the foreign key, which can also be set multiple times, is missing. The question asks for the option that lists all and only the items that can be set multiple times, so ア is wrong because it does not cover every applicable item.
- イ
正解 The correct answer is イ, foreign key and index. In a relational database, a primary key is the key used to uniquely identify each row of a table, so only one primary key can be set for a single table (even a composite primary key made up of several columns counts as just one primary key setting). A foreign key, in contrast, is a key that refers to the primary key of another table in order to link the tables, so if there are several tables you want to refer to, you can set that many foreign keys on one table. An index is an index structure for speeding up searching, and it can be created for each column that is often used for searching or sorting, so several indexes can be created on one table. Therefore the combination that lists all and only the items that can be set multiple times is the two items foreign key and index.
Incorrectウ
A primary key plays the role of uniquely identifying a row, so only one can be set for a single table and it cannot be set multiple times. ウ lists only the item that should not be listed, so it is wrong.
Incorrectエ
Foreign keys and indexes can indeed be set multiple times, but including the primary key is a mistake. If two or more primary keys were placed on one table, rows could no longer be uniquely identified, so a primary key cannot be set multiple times.
- A primary key is only one per table (it is the key that uniquely identifies a row; even a composite primary key counts as one primary key setting), while foreign keys can be set multiple times, one for each table that is referred to.
- An index is an index structure for speeding up searches, and multiple indexes can be created, one for each column. Keep in mind, however, that creating too many of them degrades update performance.