ckp*_*r02 4 sql-server identity-column
我似乎记得在MySQL中截断一个表时,自动递增的索引字段会在它停止的地方继续.因此,如果所述表被截断,最高id为100,则截断后的下一个id将为101.
有没有办法在SQL Server中执行此操作?我用超过1000行截断了我的表,但在截断后,下一个新ID在我的标识列中返回到1.我希望它继续下去.
基于 GrandMasterFlush 的答案,这里是我用来实现这种“截断但保留种子”功能的脚本,假设您的 id 是bigint.
declare @id bigint
select @id = IDENT_CURRENT('MyTable')
print(@id)
truncate table MyTable
dbcc checkident (MyTable, reseed, @id)
Run Code Online (Sandbox Code Playgroud)