I need to select a bunch of data into a temp table to then do some secondary calculations; To help make it work more efficiently, I would like to have an IDENTITY column on that
To make things efficient, you need to do declare that one of the columns to be a primary key:
ALTER TABLE #mytable
ADD PRIMARY KEY(KeyColumn)
That won't take a variable for the column name.
Trust me, you are MUCH better off doing a: CREATE #myTable TABLE
(or possibly a DECLARE TABLE @myTable
) , which allows you to set IDENTITY
and PRIMARY KEY
directly.