条件①~⑤によって,関係データベースで管理する“従業員”表と“部門”表を作成した。“従業員”表の主キーとして,最も適切なものはどれか。 〔条件〕 ① 各従業員は重複のない従業員番号を一つもつ。 ② 同姓同名の従業員がいてもよい。 ③ 各部門は重複のない部門コードを一つもつ。 ④ 一つの部門には複数名の従業員が所属する。 ⑤ 1人の従業員が所属する部門は一つだけである。 従業員
| 従業員番号 | 従業員名 | 部門コード | 生年月日 | 住所 |
|---|
部門
| 部門コード | 部門名 | 所在地 |
|---|
This question's explanation and your answers so far.
条件①~⑤によって,関係データベースで管理する“従業員”表と“部門”表を作成した。“従業員”表の主キーとして,最も適切なものはどれか。 〔条件〕 ① 各従業員は重複のない従業員番号を一つもつ。 ② 同姓同名の従業員がいてもよい。 ③ 各部門は重複のない部門コードを一つもつ。 ④ 一つの部門には複数名の従業員が所属する。 ⑤ 1人の従業員が所属する部門は一つだけである。 従業員
| 従業員番号 | 従業員名 | 部門コード | 生年月日 | 住所 |
|---|
部門
| 部門コード | 部門名 | 所在地 |
|---|
正解 A primary key is the item used to uniquely identify each row (each record) in a table of a relational database. From condition (1), the “Employee Number” is a value that each employee has exactly one of, without duplication, so no two rows share the same employee number, and this single item can reliably identify each employee. Therefore, the most appropriate primary key for the “Employee” table is “ア”, the “Employee Number”.
A composite of the “Employee Number” and the “Department Code”. Since the employee number alone can already uniquely identify a row, adding the department code is unnecessary (redundant) and violates the principle that a primary key should consist of the minimum necessary items. Therefore it is not the most appropriate.
From condition (2), “Employees with the same name may exist”, the value of the “Employee Name” can be duplicated. An item whose values can duplicate cannot uniquely identify a row, so it cannot serve as a primary key.
From condition (4), “Multiple employees belong to one department”, the “Department Code” can take the same value across multiple employee rows. Since it cannot uniquely identify a row, it cannot serve as a primary key (it corresponds to a foreign key that references the “Department” table).