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

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

    Is it possible to have another int column on your table variable and update that column with modulo after the insert is finished?

    declare @Mytablevar table
    (
    id int identity(1,1)
    ,id1 int
    somedata nvarchar(300)
    )
    
    -- insert your data as you would.  After insert is finished, do the following:
    
    update @mytablevar set id1 = case when id > 250 then id % 250 else id end
    

提交回复
热议问题