如何将身份规范添加到主键列
问题描述:
大家好,
我有一个名为Tax的表,该表具有列(TaxId,TaxPercentage).
TaxId是主键.现在,我想将TaxId设置为身份.
怎么做.
我无法使用设计器来执行此操作,因为sql-server2008-R2不允许我将设计器用于现有表.我在Google上进行了大量搜索,但找不到正确的查询.
hello all,
i have a table named Tax , which has columns (TaxId, TaxPercentage).
TaxId is primarykey. Now i want to set TaxId to be identity.
How to do this.
I cannot use designer to do this as sql-server2008-R2 is not allowing me to use designer for already existing table. I searched alot for this on google but was unable to find the right query.
答
检查这些链接..
sqlserver主键约束和唯一键约束[ ^ ]
sqlserver如何删除主键约束[ ^ ]
sqlserver在列上添加或删除标识属性[ ^ ]
希望对您有帮助
check these links..
sqlserver primary key constraints and unique key constraints[^]
sqlserver how to drop primary key contraint[^]
sqlserver add or remove identity property on column[^]
hope it helps
IF OBJECT_ID ('Tax', 'U') IS NOT NULL
DROP TABLE Tax;
GO
CREATE TABLE Tax
(
TaxId int IDENTITY(1,1),
);
嘿,
更改现有表,请尝试以下
hey,
to alter existing table try following
Alter Table Tax
Add TaxId_new Int Identity(1, 1)
Go
Alter Table Tax Drop Column TaxID
Go
Exec sp_rename 'Tax.TaxId_new', 'TaxID', 'Column'
希望对您有帮助
祝你好运
快乐编码:)
Hope it will help u
Best Luck
Happy Coding :)