简体   繁体   English

只能有一个外键引用主键吗?

[英]Can only one foreign key reference a primary key?

When creating a table and a database in do the foreign keys need to be unique? 在创建表和数据库时,外键需要是唯一的吗?

For example 例如

Table: Manifest 表: 清单

Manifest_Barcode - PK
Vehicle_reg - FK
weight
description

Table: Vehicle 表: 车辆

vechicle_reg - PK
employee_ID - FK
make
model

Table: Drivers 表: 驱动程序

employee_ID - PK
vechicle_reg - FK
name
adress
phone_Number
year

Or, can I use the same foreign key in 2 different tables? 或者,我可以在2个不同的表中使用相同的外键吗? Like the above? 喜欢上面的?

It is completely appropriate and quite normal to have multiple FOREIGN KEYs that refer to the same PRIMARY KEY. 具有引用相同PRIMARY KEY的多个FOREIGN KEY是完全合适且非常正常的。 They are not the same FOREIGN KEY (they will each build a separate index to use in enforcing the key), they are different FOREIGN KEYs with similar definitions. 它们不是相同的 FOREIGN KEY(它们将构建一个单独的索引用于强制执行密钥),它们是具有相似定义的不同FOREIGN KEY。

Note that you will have to create the table vehicle1 before declaring either of the FOREIGN KEYs. 请注意,在声明任一FOREIGN KEY之前,您必须创建表vehicle1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM