在SQL Server中,“标识”列属性是什么意思?

时间:2022-10-10 22:31:39

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

我第一次使用SQL Server,我看到一个列属性被称为Identity。

What does this mean?

这是什么意思?

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

将列属性标记为Identity = Yes的优点是什么?

5 个解决方案

#1


28  

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:

它仅仅意味着该列使用Identity(seed, increment)函数来为主键(通常)提供值。它也被称为“自动编号”。下面第二行是一个例子:

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
)

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.

它作为每个记录递增的列的默认值。注意,还可以从SCOPE_IDENTITY()中插入值。不要使用@@IDENTITY,因为它被折旧,在触发器或嵌套上下文的情况下可能返回错误的结果。

#2


4  

Flag indicating an Identity Column - can be used as an auto-increment column (recommended for any table)

指示标识列的标志——可以用作自动增量列(推荐用于任何表)

it has many implications like being able to get the id of the last inserted row in a table using @@IDENTITY or SCOPE_IDENTITY() etc.

它有很多含义,比如能够使用@@IDENTITY或SCOPE_IDENTITY()等获得表中最后插入的行的id。

Try: Understanding Identity Columns

试一试:了解标识列

#3


1  

It's equivalent to MySQL's AUTO_INCREMENT property. Usually used on a primary key column

它等价于MySQL的AUTO_INCREMENT属性。通常用于主键列

#4


0  

http://sqlskills.com/BLOGS/KIMBERLY/post/Ever-increasing-clustering-key-the-Clustered-Index-Debateagain!.aspx

http://sqlskills.com/BLOGS/KIMBERLY/post/Ever-increasing-clustering-key-the-Clustered-Index-Debateagain !是

#5


0  

All features of SQL Server IDENTITY property of columns. And a handy procedure to monitor all Identity columns. http://www.sqllion.com/2011/08/identity-in-sql/

列的SQL Server标识属性的所有特性。以及监视所有标识列的方便过程。http://www.sqllion.com/2011/08/identity-in-sql/

#1


28  

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:

它仅仅意味着该列使用Identity(seed, increment)函数来为主键(通常)提供值。它也被称为“自动编号”。下面第二行是一个例子:

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
)

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.

它作为每个记录递增的列的默认值。注意,还可以从SCOPE_IDENTITY()中插入值。不要使用@@IDENTITY,因为它被折旧,在触发器或嵌套上下文的情况下可能返回错误的结果。

#2


4  

Flag indicating an Identity Column - can be used as an auto-increment column (recommended for any table)

指示标识列的标志——可以用作自动增量列(推荐用于任何表)

it has many implications like being able to get the id of the last inserted row in a table using @@IDENTITY or SCOPE_IDENTITY() etc.

它有很多含义,比如能够使用@@IDENTITY或SCOPE_IDENTITY()等获得表中最后插入的行的id。

Try: Understanding Identity Columns

试一试:了解标识列

#3


1  

It's equivalent to MySQL's AUTO_INCREMENT property. Usually used on a primary key column

它等价于MySQL的AUTO_INCREMENT属性。通常用于主键列

#4


0  

http://sqlskills.com/BLOGS/KIMBERLY/post/Ever-increasing-clustering-key-the-Clustered-Index-Debateagain!.aspx

http://sqlskills.com/BLOGS/KIMBERLY/post/Ever-increasing-clustering-key-the-Clustered-Index-Debateagain !是

#5


0  

All features of SQL Server IDENTITY property of columns. And a handy procedure to monitor all Identity columns. http://www.sqllion.com/2011/08/identity-in-sql/

列的SQL Server标识属性的所有特性。以及监视所有标识列的方便过程。http://www.sqllion.com/2011/08/identity-in-sql/