本文介绍了如何将身份规范添加到主键列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个名为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.
推荐答案
IF OBJECT_ID ('Tax', 'U') IS NOT NULL
DROP TABLE Tax;
GO
CREATE TABLE Tax
(
TaxId int IDENTITY(1,1),
);
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 :)
这篇关于如何将身份规范添加到主键列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!