Can we rollback to original state after we have used DBCC CHECKIDENT to restart Identity column count?

前端 未结 1 584
迷失自我
迷失自我 2021-01-14 04:57

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 fr

相关标签:
1条回答
  • 2021-01-14 05:57

    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)
    
    0 讨论(0)
提交回复
热议问题