本文介绍了使用 DBCC CHECKIDENT 重新启动 Identity 列计数后,是否可以回滚到原始状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前在某些操作中,我必须删除旧数据并插入新数据.但我注意到,尽管删除了数据,但标识列并未重置并从其最后一个最大值继续.因此,我使用 DBCC CheckIdent 来实现在交易中发生的所有这些相同的事情.我可以将事务回滚到初始状态吗?DBCC CHECKIDENT 会不会造成任何问题?请指导...

Currently on some operations I have to delete the old data and insert new one. But I noticed that inspite of deleting data the identity column did not reset and continued from its last max value. So i used the DBCC CheckIdent for achieve the same all this is taking place within a trasaction. Can i rollback the transaction back to the intital state ? Would the DBCC CHECKIDENT pose any problems ? Kindly guide...

推荐答案

下面的测试代码显示DBCC动作可以回滚:

The test code below shows that the DBCC action can be rolled back:

create table #t
(id int identity, val1 int)
go

insert #t (val1)
values (1),(2),(3)

select MAX(id) AS before from #t

begin tran 

    delete #t

    dbcc checkident (#t, reseed,0)

    select MAX(id) AS inside_tran from #t   

rollback

select MAX(id) as after_rollback from #t
dbcc checkident (#t, noreseed)

这篇关于使用 DBCC CHECKIDENT 重新启动 Identity 列计数后,是否可以回滚到原始状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 16:39