[英]How to add Identity Column in SQL server?
You can only have 1 Identity Column per Table. 每个表只能有1个标识列。 So if you don't have one already, Just alter the table and add the Column. 因此,如果您还没有一个,只需更改表并添加列。 Like this 像这样
ALTER TABLE YourTableName
ADD IdCol INT IDENTITY(1,1)
You can rename your previous ID column to keep those values if you need them in your application 您可以重命名以前的ID列以保留这些值(如果需要在应用程序中使用它们)
EXEC sp_rename 'TableName.id', 'oldid', 'COLUMN';
Then add new ID column with Unique constraint as follows 然后添加具有唯一性约束的新ID列,如下所示
Alter table TableName Add id int identity(1,1) unique not null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.