如何更改SQL Server 2008中的标识属性?

时间:2022-03-14 11:50:51

I have a table which has no identity column. I want to change a column's identity specification, but SQL Server 2008 doesn't allow that. So, how can I change identity property in SQL Server 2008?

我有一个没有标识列的表。我想更改列的标识规范,但SQL Server 2008不允许这样做。那么,我如何在SQL Server 2008中更改身份属性?

2 个解决方案

#1


under tools-->options-->designers-->table and database designers

在工具 - >选项 - >设计师 - >表和数据库设计者

uncheck prevent saving changes that require table re-creation

取消选中阻止保存需要重新创建表的更改

#2


If you want to add a new column as an identity column:

如果要将新列添加为标识列:

ALTER TABLE [tablename] ADD COLUMN [columnName] int NOT NULL IDENTITY(1,1)
GO
ALTER TABLE [tablename] ADD PRIMARY KEY ([columnName])

If you're trying to use the SQL 2008 designer, there is a setting you have to disable so that the designer can drop and recreate the table.

如果您尝试使用SQL 2008设计器,则必须禁用一个设置,以便设计人员可以删除并重新创建表。

#1


under tools-->options-->designers-->table and database designers

在工具 - >选项 - >设计师 - >表和数据库设计者

uncheck prevent saving changes that require table re-creation

取消选中阻止保存需要重新创建表的更改

#2


If you want to add a new column as an identity column:

如果要将新列添加为标识列:

ALTER TABLE [tablename] ADD COLUMN [columnName] int NOT NULL IDENTITY(1,1)
GO
ALTER TABLE [tablename] ADD PRIMARY KEY ([columnName])

If you're trying to use the SQL 2008 designer, there is a setting you have to disable so that the designer can drop and recreate the table.

如果您尝试使用SQL 2008设计器,则必须禁用一个设置,以便设计人员可以删除并重新创建表。