Skip to content

平成22年度 春期 ITパスポート試験 問83

This question's explanation and your answers so far.

問83
頻出度★★★

関係データベースにおいて主キーを指定する目的はどれか。

出典 平成22年度 春期 ITパスポート試験 問83
解説

問 83

  • Incorrectア

    The purpose of a primary key is not to identify multiple records at the same time; it is the opposite — to narrow things down to just one record. Because a primary key carries a uniqueness constraint, no two rows hold the same value, so specifying a primary key value always leaves exactly one matching row. When you want to retrieve several rows together, you use a non-primary-key column such as a department code as the condition. This option therefore states the exact opposite of the purpose of specifying a primary key.

  • イ

    正解 The correct answer is イ. In a relational database, data is managed in the form of tables made up of rows (records) and columns (attributes). Without a marker that reliably tells you which row is being referred to, you cannot update, delete, or reference data. The column (or combination of columns) specified in order to distinguish one row in a table from the other rows and pin it down is the primary key. A column designated as the primary key is subject to two constraints: its values must not be duplicated (uniqueness constraint), and its values must not be empty (NULL) (not-null constraint). When both hold, giving a single primary key value always determines exactly one matching row. For example, if the employee number is made the primary key of an employee table, even when two employees share the same name, one person can still be reliably identified by the employee number. In other words, the purpose of specifying a primary key is to make a record (row) uniquely identifiable, so イ is correct.

  • Incorrectウ

    Search conditions can be freely specified on columns that are not the primary key; searching by name or by date of hire, for example, can be done regardless of whether a primary key is specified. Therefore “making it possible to specify search conditions” is not a reason to set up a primary key. A primary key usually gets an index created for it automatically, which makes searching faster, but that is an incidental benefit arising from guaranteeing uniqueness, not the purpose of specifying a primary key itself.

  • Incorrectエ

    Whether a column can be the target of arithmetic operations such as addition or averaging depends on whether its data type is numeric, and has nothing to do with whether it is the primary key. Primary keys often use string-type columns such as employee codes or product codes, and in that case the primary key cannot be the target of arithmetic operations. Conversely, a numeric column that is not the primary key can be used in calculations as usual, so this explanation does not hold up as the purpose of a primary key.

ここがポイント
  • A primary key is the column (attribute), or combination of columns, specified in a table of a relational database in order to uniquely identify a single row (record). It carries two constraints — values must not be duplicated (uniqueness) and must not be empty (NULL) (not null) — and these ensure that a primary key value determines exactly one row.
  • When a single column is not enough to be unique, a composite key that combines several columns is used as the primary key. In addition, a column that references another table's primary key and links tables together is called a foreign key; the correspondence between primary keys and foreign keys is the basis for relating tables in a relational database.
用語

Your answers