如何将身份规范添加到主键列 [英] How to add identity specification to a primary key column

查看:87
本文介绍了如何将身份规范添加到主键列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个名为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 :)


这篇关于如何将身份规范添加到主键列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆