How can I reseed an identity column in a T-SQL table variable?

后端 未结 5 1425
梦毁少年i
梦毁少年i 2020-12-08 09:34

I have a T-SQL table variable (not a table) which has an auto incrementing identity column. I want to clear all data from this variable and reset the identi

5条回答
  •  既然无缘
    2020-12-08 10:24

    If you need to truncate the table variable in each turn of a while loop, you can put the declare @myTbl (...) statement in the loop. This will recreate the table and reset the identity column on each turn of the loop. However, it has a heavy performance hit. I had fairly tight loop, and redeclaring the table variable relative to delete @myTbl was several times slower.

    • Dan

提交回复
热议问题