MySQL - 新手问题:这些表的 PK 和 FK 是什么? [英] MySQL - Newbie question: Which are the PK and the FK for these tables?
问题描述
我有 3 张桌子:
员工 T
emp_id |姓名 |地址
emp_id | name | address
T 部
dep_id |名字
工资标准
emp_id |dep_id |月 |年 |工资
emp_id | dep_id | month | year | salary
对于每个表,主键和外键分别是什么?
For each table, what are the primary keys and the foreign keys?
我的回答:
表名|PK |FK|
- 员工:emp_id |dep_id
- 部门:dep_id ||emp_id
- 薪资:emp_id、dep_id |emp_id,dep_id
我的回答正确吗?
推荐答案
Employees
和 Department
表有主键(你猜对了),但没有外键.
The Employees
and Department
tables have primary keys (which you got correct), but no foreign keys.
在Salaries
中,emp_id
和dep_id
都是外键.
Salaries
没有单一的主键,尽管 emp_id
、dep_id
、month
和 year
可能是一个复合键(因为这 4 个的组合总是唯一的,假设一个员工每个月只被一个部门支付一次工资:)).
There's no single primary key on Salaries
, although emp_id
, dep_id
, month
and year
could possibly be a composite key (as the combination of these 4 would always be unique, assuming an employee is only salaried once per month by a department :) ).
这篇关于MySQL - 新手问题:这些表的 PK 和 FK 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!