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'
温馨提示:答案为网友推荐,仅供参考
相似回答