是否可以将重复值插入主键列? [英] is it possible to insert the duplicate values into a primary key column?

查看:90
本文介绍了是否可以将重复值插入主键列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含主键的列。

我使用连接查询在另一个表中使用相同的列?在另一个表中使用相同的列之后是否可以插入重复的值?

提前感谢

i have a column that contains primary key.
i use the same column in another table by using join query? after using the same column in another table is it possible to insert duplicate values?
thanks in advance

推荐答案

你在谈论的是什么您的问题称为 FOREIGN KEY [ ^ ]



您无法在主键列中插入重复值。主键列是唯一的。



让我们看看外键是如何工作的。当表具有1米关系时,通常在表中创建外键列。考虑员工部门方案。 1个部门可以有很多员工。因此,您在employees表中创建外键DepartmentId(来自Department表的主键)。

现在回答您的问题,是的,此列可能有重复/重复值,因为可能有超过1名员工一个部门。



我希望能解除你的怀疑。
What you are talking about in your question is called FOREIGN KEY[^]

You cannot insert duplicate values in a primary key column. Primary key columns are unique.

Lets see how foreign key works. You usually create foreign key column in a table when the tables have 1-m relationship. Consider Employee-Department scenario. 1 department can have many employees. So you create foreign key DepartmentId (primary key from Department table) in employees table.
Now to answer your question, yes this column may have duplicate/repeated values because the there could be more than 1 employee in a department.

I hope that clears your doubt.


简单,



主键在其名称中有自己的定义,意味着它不能允许重复值甚至是空值。

你说的是FOREIGN键。它是其他表的列。

因此,根据您的要求,它将是1-1,1-多,多-1,多 - 多关系。

所以是的它允许您在引用键列中输入重复值。
Simple,

Primary key has its own defination in its name , means that it can not allow duplicate values even null value.
And you are talking about FOREIGN key. it is the column of other table .
So depend your requirement it will be 1-1,1-Many, Many-1, Many-Many relationships.
So yes it will allowing you to enter duplicate value in reference key columns.


这篇关于是否可以将重复值插入主键列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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