SQL语句实现取消自增列属性

1如果仅仅是指定值插入可用以下语句临时取消

 

SET IDENTITY_INSERT TableName ON

INSERT INTO tableName(xx,xx) values(xx,xx)

SET IDENTITY_INSERT TableName OFF

 

2新增一列删除自增列修改改列名

 

alter table a add xxx int

update a set xxx=id

alter table a drop column id

exec sp_rename 'xxx', 'id', 'column'

 

3通过修改系统关于该表的列属性该方法使用不当将可能引起其它不可预料的错误

 

sp_configure 'allow update',1

reconfigure with override

go

update syscolumns set colstat=0 where colstat=1 and id=object_id('tablename')

go

sp_configure 'allow update',0

reconfigure with override

原文地址:https://www.cnblogs.com/qanholas/p/2169560.html