简体   繁体   中英

Having a foreign key as the primary key in a child table

In a One to Many association between a Parent Table and Child Table.

Is it ok to make the Foreign key on the Child table as the Primary key on the same child table.

Just working my way through DBMS and would appreciate expert views on these type of designs.

What are the Pros and Cons?

If you mean one parent row maps to many child rows, then you won't be able to do that. Primary key values come with unique key constraints; if you need multiple child rows to reference the same parent, setting the foreign key reference as the primary key will disallow that, because you won't be able to have more than one row with the same foreign key reference.

这将创建1:0-1关系,而不是1:0-n,因为定义将子项与父项关联的外键,因为子项的主键将阻止您拥有多个具有相同父键的子项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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