Programmatically set identity seed in a table variable

后端 未结 3 808
你的背包
你的背包 2021-01-18 06:30

I need to create a table variable with an identity seed that starts with the max value of a field in another table?

I\'ve tried this:

DECLARE @Identi         


        
3条回答
  •  滥情空心
    2021-01-18 07:17

    I believe you can do this, but it'll have to be done in dynamic SQL - declare the tableVar in the dynamic SQL and use it there too!

    It would surely be easier and result in faster code if you started it at 1 and had a secondary ID field that is calculated as MAX(HHRecId) + ID.

提交回复
热议问题