Is there anyway to reset the identity of a Table Variable?

前端 未结 12 2027
无人及你
无人及你 2020-12-17 15:33

Say I have a table variable:

DECLARE @MyTableVar TABLE (ID INT IDENTITY(1,1), SomeData NVARCHAR(300))

After I have inserted 250 rows, I nee

12条回答
  •  太阳男子
    2020-12-17 15:53

    I tried it on net but i am not able to get any solution on reset identity for table variable.

    If you are able to use temp table #MyTableVar instead of table @MyTableVar variable then it is possible to reset identity value

       DBCC CHECKIDENT('TableName', RESEED, NewValue)
    
       DBCC CHECKIDENT(#MyTableVar, RESEED, 0)
    

    Newvalue must be one less than the newIdentiyValue

       NewValue= NewIdentity-1;
    

    If you still want to learn more you can refer my blog http://tryconcepts.blogspot.in/2012/08/reset-identity-column-to-new-id.html

提交回复
热议问题