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

前端 未结 12 2052
无人及你
无人及你 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:38

    You can't reseed the identity value on a Table Variable but you can do the same thing with a Temp Table:

    CREATE  TABLE #TAB(ID INT IDENTITY,VALUE VARCHAR(10))
    DECLARE @RESEED INT = 32
    DBCC CHECKIDENT(#TAB,RESEED,@RESEED)
    INSERT INTO #TAB  
    SELECT 'TEST'
    SELECT * FROM #TAB  
    

提交回复
热议问题