mssql 如何更新标识列


update book set bookid=46080 where bookid=72708
其实bookid为自增长列,执行报如下错误”无法更新标识列 'bookid'。“
通过设置identity_insert为on依然不行。
set identity_insert booklistinfo ON;

mssql 数据库

BAI肄CHI 12 years, 2 months ago

----允许对系统表进行更新
exec sp_configure 'allow updates',1
reconfigure with override
GO

----取消标识列标记
update syscolumns set colstat = 0 where id = object_id('tablename') and colstat = 1
GO

--插入id=8001-8003的行
...

----恢复标识列标记
update syscolumns set colstat = 1 where id = object_id('tablename') and name = '标识列名称'

----重新设置标识的起始值
DBCC CHECKIDENT (表名称, RESEED, 10003)

----禁止对系统表进行更新
exec sp_configure 'allow updates',0
reconfigure with override
GO
这种方法蛮繁锁的。

WINNER answered 12 years, 2 months ago

Your Answer