This question's explanation and your answers so far.
問86
頻出度★★★
P 社は,セキュリティを確保するために自社ビルを 10 の区画に分け,各区画への入退室を IC カードで行うシステムを導入し,その管理方法についての検証を始めた。この IC カードを使った入退室管理(以下,入退室管理という)の概要は次のとおりであり,入退室管理で用いるデータベースの構造(一部)を図 1 に示す。
〔入退室管理の概要〕
(1) 社員は一つの部署に所属し,IC カードを 1 人 1 枚貸与される。IC カードはカード固有の IC カード番号をもつ。IC カードの情報は IC カード登録表に登録される。
(2) 社員の入退室が許可されている区画は個別に決められており,許可された区分の情報が入退室許可表に登録される。入退室が可能な場合で,その区画が所属部署の入っている区画の場合は “1”,それ以外で入退室が必要と認められた区画の場合は “2” が,入退室許可表の許可区分に登録される。
(3) 各区画には IC カードリーダが設置されており,入退室が許可された IC カード番号を読み取ったときだけドアを解錠し,入退室の記録を入退室記録表に記録する。このとき,入室の場合は “1”,退室の場合は “−1” を入退室記録表の入退室区分に記録する。
なお,P 社は,社員に対して午前 0 時までに退社することを義務づけている。
入退室許可表のレコードを一意に決めるための主キーとして,適切なものはどれか。ここで,下線は主キーを表す。
社員番号
区画番号
許可区分
(下線:社員番号)
社員番号
区画番号
許可区分
(下線:社員番号, 区画番号)
社員番号
区画番号
許可区分
(下線:社員番号, 許可区分)
社員番号
区画番号
許可区分
(下線:社員番号, 区画番号, 許可区分)
出典 平成27年度 春期 ITパスポート試験 問86
解説
問 86
//
×Incorrectア
If only the employee number is made the primary key, one employee can have only one row. In reality, however, one employee holds entry/exit permissions for several zones, so multiple rows with the same employee number exist and a record cannot be identified uniquely.
○イ
正解The entry/exit permission table records which employee may enter which zone under which permission category, so it is an intermediate (junction) table that mediates the many-to-many relationship between employees and zones. One employee can hold permissions for several zones, and conversely one zone can be permitted to several employees. Therefore the employee number alone, or the zone number alone, leaves several rows with the same value, and a record cannot be identified uniquely. Only when the two columns employee number and zone number are combined is the permission of that employee for that zone fixed to a single row. The remaining permission category is determined dependently once that combination is fixed, so it is not included in the primary key. Hence イ, which underlines the two columns employee number and zone number, is the appropriate primary key.
×Incorrectウ
The combination of employee number and permission category does not become unique. The permission category is only one of a few classification values such as always permitted or limited to a time slot, so the same employee can have rows for several zones with the same permission category. Moreover, the permission category is a dependent attribute whose value is determined by the primary key, so making it a component column of the primary key is inappropriate.
×Incorrectエ
If all three columns are made the primary key, the rows do become unique, but uniqueness is already guaranteed by the two columns employee number and zone number alone, so the permission category is superfluous. A primary key must be the minimal combination of columns that can identify a record uniquely (minimality), so エ, which contains a redundant column, is not appropriate as a primary key.
ここがポイント
A primary key is the minimal combination of columns that can uniquely identify a record in a table and contains no superfluous columns. When no single column can guarantee uniqueness, a composite (concatenated) primary key made up of several columns is used.
In an intermediate (junction) table that represents a many-to-many relationship, the primary key is the combination of the keys of the entities on both sides, and the other columns are attributes dependent on that primary key.