我应该分配给我的表是什么PK和FK? [英] What is the PK and FK i should assign to my table?

查看:501
本文介绍了我应该分配给我的表是什么PK和FK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一家公司为高级职员提供运输服务。
有3张表:DRIVERS,VEHICLES,STAFFS。

A company provides transport services to high-ranked staffs. There are 3 tables: DRIVERS, VEHICLES, STAFFS.

DRIVERS
- 许可证号码[PK]
- name
- 使用的语言
- ...(等等)

DRIVERS - license number [PK] - name - language spoken - ... (and so on..)

车辆
- 车辆ID [PK]
- 注册号
- 模型
- 颜色
- ...等等...

VEHICLES - vehicle ID [PK] - registration number - model - colour - ... and so on...

STAFFS
- ID [PK]
- name
- 位置名称
- ...等等....

STAFFS - staff ID [PK] - name - position name - ... and so on....

创建一个名为ORGANIZE
的新表,它将分配一个驱动程序和一个车辆以匹配工作人员的需要。
什么是PK和FK?

I want to create a new table called ORGANIZE whereby, it will assign a driver and a vehicle to match the needs of the staff. what will be the PK and FKs?

推荐答案

我写了一个更详尽的答案在你的另一个问题。

数据库的标准化

I've written a more exhaustive answer over at your other question.
normalization of database

如果你需要将一个司机和一个车辆匹配到一个职员,那么你可以做一个三列复合pk与fk关联与其他三个表。你需要连接你自己的逻辑来实际做组织...这不会在数据库中完成,数据库应该保留组织的结果。

If you need to match a driver and a vehicle to a staff member, then you can do a three column composite pk with fk associations with the three other tables. You'll need to wire up your own logic to actually do the organization... this would not be done in the database, the db should just retain the results of the organization.

这篇关于我应该分配给我的表是什么PK和FK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆