接到开发人员反馈原来能正常插入的数据现在插入报错,查看报错明细是报违反主键唯一性,主键是自增的ID字段。
插入指定的ID值不会报错。
按照报错基本确定是自增字段的初始值出现问题导致的。
解决方法:
-- 使用DBCC CHECKIDENT语句重置起始值
select max(id) from testtable--14376
dbcc checkident('testtable',reseed,14376)
彻底解决:
Open SQLServer configuration manager from your server. Select SQL Server 2012 instance there right client and select Properties menu. You will find a tabbed dialog window. You select start up parameters tab from there and register -t272. Then restart SQL Server 2012 instance again and see the difference
参考:https://www.codeproject.com/tips/668042/sql-server-2012-auto-identity-column-value-jump-is