将外键作为子表中的主键 [英] Having a foreign key as the primary key in a child table

查看:215
本文介绍了将外键作为子表中的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在父表和子表之间的一对多关联中。



将Child表上的外键设置为相同的孩子表。



只需通过DBMS工作,并欣赏这些类型设计的专家意见。



有哪些优点和缺点?

解决方案

一个父行映射到许多子行,那么您将无法做到这一点。主键值具有唯一的键约束;如果您需要多个子行来引用同一个父项,则将外键引用设置为主键将不允许,因为您不能拥有多个具有相同外键引用的行。


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.

这篇关于将外键作为子表中的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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