SQL已有表中(无标识列)怎么样修改为有标识列如改为identity(1,2)

如题所述

alter table 表名 drop constraint // 如果没有外健约束可以不执行

select 自增列名=identity(int,1,1) --指定需要的列
into 临时表名 from 表名
drop table 表名
exec sp_rename '临时表名','表名'

alter table 表名 add constraint //如果没有外健约束删除了,重新增加

完整代码如下 : aa 为表名 id 为自增列 bb为临时表

select id=identity(int,1,1) --指定需要的列
into bb from aa
drop table aa
exec sp_rename 'bb,'aa'
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网