午夜精品久久久久久久99老熟妇,天堂中文www官网,未满十八18勿进黄网站,太粗太深了太紧太爽了,天天爽夜夜爽夜夜爽

考試報名
考試報名
考試內(nèi)容
考試大綱
在線客服
返回頂部

備考刷題,請到

CDA認(rèn)證小程序

For the table: emp(empno, ename, sal, deptno), where fields represent employee id, name, salary and department number; and dept(deptno, dname), where fields represent department number and name. Which of the following statements about foreign key constraints is correct?
A. Set empno in emp table as foreign key
B. Set deptno in emp table as foreign key
C. Set deptno in dept table as foreign key
D. Cannot set foreign key
上一題
下一題
收藏
點贊
評論
題目解析
題目評論(0)

Based on the relationship between tables emp and dept, one department can have multiple employees, while one employee only belongs to one department. Therefore, empno in emp table can be set as primary key, and deptno as foreign key. Or deptno in dept table can be set as primary key.

正確答案是B:Set deptno in emp table as foreign key。

專業(yè)分析如下:

在關(guān)系數(shù)據(jù)庫中,外鍵(Foreign Key)是用來建立和強化兩個表之間的連接的。外鍵的作用是保證引用完整性,即確保一個表中的數(shù)據(jù)在另一個表中是存在的。

具體到題目中的兩個表:
1. `emp` 表(員工表),包含字段 `empno`(員工編號)、`ename`(員工姓名)、`sal`(工資)、`deptno`(部門編號)。
2. `dept` 表(部門表),包含字段 `deptno`(部門編號)、`dname`(部門名稱)。

從業(yè)務(wù)邏輯上看,每個員工屬于一個部門,因此 `emp` 表中的 `deptno` 字段應(yīng)該引用 `dept` 表中的 `deptno` 字段。這意味著 `emp` 表中的 `deptno` 字段應(yīng)當(dāng)是一個外鍵,指向 `dept` 表中的 `deptno` 字段。

因此,正確的外鍵設(shè)置是將 `emp` 表中的 `deptno` 字段設(shè)置為外鍵,引用 `dept` 表中的 `deptno` 字段。

其他選項的分析:
A: Set empno in emp table as foreign key
- `empno` 是員工表中的主鍵,不應(yīng)作為外鍵。

C: Set deptno in dept table as foreign key
- `deptno` 是部門表中的主鍵,不應(yīng)作為外鍵。

D: Cannot set foreign key
- 這是錯誤的,因為根據(jù)業(yè)務(wù)需求,`emp` 表中的 `deptno` 應(yīng)該是 `dept` 表中的 `deptno` 的外鍵。

綜上所述,正確答案是B。