简体   繁体   English

SQL Server 2005中的自动增量

[英]Auto Increment in SQL server 2005

How to add auto incrementing property to primary key of a table in Sql Server 2005 ? 如何在SQL Server 2005中向表的主键添加自动递增属性? I have ProductID as primary key. 我将ProductID作为主键。 I want to increment its value by 1 everytime a record is added. 我想在每次添加记录时将其值增加1。 I didn't use IDENTITY keyword while creating table. 创建表格时,我没有使用IDENTITY关键字。

There is a lot posted about this either here in SO or in other places. 无论是在SO还是在其他地方,都有很多关于此的文章。 What you are looking for is exactly this 您正在寻找的正是这个

how to set auto increment after creating a table without any data loss?

Thank you everyone . 谢谢大家 。 i have found another way of adding IDENTITY property without sql commands. 我发现了另一种无需SQL命令即可添加IDENTITY属性的方法。

In SQL Server Management console , go to Object Explorer->Select your Database->Select your Table->Right click on the Column on which Identity property has to be specified->Choose Modify option. 在SQL Server管理控制台中,转到“对象资源管理器”->“选择数据库”->“选择表”->右键单击“必须在其上指定身份属性的列”->“选择修改”选项。 In column Poperties window , scroll to Identity Specification . 在“ Poperties”窗口中,滚动到“ Identity Specification”。 Change value of IsIdentity to Yes and specify seed and increment values and save. 将IsIdentity的值更改为Yes,并指定种子和增量值并保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM