主键和身份之间有什么区别

主键和身份之间有什么区别

本文介绍了主键和身份之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL Server数据库中,主键和标识列之间有什么区别?列可以是主键,而不是缩进。然而,列不能成为一个身份而不是主键。

In a SQL Server db, what is the difference between a Primary Key and an Identity column? A column can be a primary key without being an indentity. A column cannot, however, be an identity without being a primary key.

除了差异之外,PK和Identity列提供的只是一个PK列吗?

In addition to the differences, what does a PK and Identity column offer that just a PK column doesn't?

编辑:糟糕。如下所述,现在由我验证,列可以是身份,而不是PK。当我测试这个,我的列类型是一个字符串,我无法将其设置为一个身份。

edit: Oops. As pointed out below and now verified by me, a column can be an identity without being a PK. When I tested this, my the column type was a string and I was unable to set it to an identity. Makes sense.

推荐答案

一列不一定是PK,肯定是一个身份。

A column can definitely be an identity without being a PK.

身份只是一个自动增加列。

An identity is simply an auto-increasing column.

主键是定义行的唯一列或列。

A primary key is the unique column or columns that define the row.

这两个经常一起使用,但不要求这样做。

These two are often used together, but there's no requirement that this be so.

这篇关于主键和身份之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 02:28