编辑:
在花了几个小时比较整个页面转储之后,我意识到有一种更简单的方法,我应该留在DMV上。
该值在备份/还原后仍然有效,这清楚地表明了该值已存储-我转储了数据库中的所有页面,但是找不到添加记录时的位置/更改。比较20万行的页面转储并不是一件好事。
我使用了专用的管理控制台,对每个暴露的内部表都进行了转储,插入了一行,然后又对系统表进行了转储。这两个转储是相同的,这表明它可以生存,因此必须进行存储,即使在该级别也没有暴露。
因此,绕了一圈后,我意识到DMV确实有答案。
create table foo (MyID int identity not null, MyField char(10))insert into foo values ('test')go 10-- Inserted 10 rowsselect Convert(varchar(8),increment_value) as IncrementValue, Convert(varchar(8),last_value) as LastValuefrom sys.identity_columns where name ='myid'-- insert another rowinsert into foo values ('test')-- check the values againselect Convert(varchar(8),increment_value) as IncrementValue, Convert(varchar(8),last_value) as LastValuefrom sys.identity_columns where name ='myid'-- delete the rowsdelete from foo-- check the DMV againselect Convert(varchar(8),increment_value) as IncrementValue, Convert(varchar(8),last_value) as LastValuefrom sys.identity_columns where name ='myid'-- value is currently 11 and increment is 1, so the next insert gets 12insert into foo values ('test')select * from fooResult:MyID MyField----------- ----------12 test(1 row(s) affected)仅仅因为行被删除,最后一个值没有被重置,所以最后一个值+增量应该是正确的答案。
也要在我的博客上写剧集。
哦,这是所有方法的捷径:
select ident_current('foo') + ident_incr('foo')因此,事实证明这很容易-但这一切都假设在您找回ID时,没有其他人使用过您的ID。可以进行调查,但是我不想在代码中使用它。



