什么是“身份”在SQL Server中的列属性是什么意思? [英] What does "Is Identity" column property mean in SQL Server?

查看:456
本文介绍了什么是“身份”在SQL Server中的列属性是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用 SQL Server ,我发现列属性称为是身份

I am using SQL Server for the first time and I see that a column property is called Is Identity.

这是什么意思?

将列属性标记为 Is Identity = Yes 有什么好处?

What are the advantages of marking a column property as Is Identity = Yes?

推荐答案

这只是意味着列使用 Identity(seed,increment)对于主键(通常)。它也被称为自动编号。下面的第二行是一个例子:

It simply means the column uses the Identity(seed, increment) function to provide values for a primary key (usually). It is also known as "Autonumber". The second line below is an example:

CREATE TABLE Table (
TableID bigint IDENTITY(1,1) NOT NULL,
DateTimeStamp datetime NOT NULL DEFAULT (getdate()),
Data nvarchar(100) NOT NULL,
CONSTRAINT PK_Table PRIMARY KEY CLUSTERED 
(
    TableID ASC
)

它作为每个记录递增的列的默认值。也可以获取从SCOPE_IDENTITY()插入的值。不要使用@@ IDENTITY,因为它是贬值的,并且在触发器或嵌套上下文的情况下可能返回错误的结果。

It acts as a default value for the column that increments for each record. Note that you can also get the value inserted from SCOPE_IDENTITY(). Do not use @@IDENTITY as it is depreciated and can return the wrong result in the case of triggers or nested contexts.

这篇关于什么是“身份”在SQL Server中的列属性是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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