Reputation: 187
I have an MSSQL table with no id column, mainly because I accidentally dropped it and so recreated the column. Is there a way in SQL of automatically adding values to it so I don't have to manually sit there putting an ID number?
Upvotes: 0
Views: 68
Reputation: 674
Solutions 1: Restore Latest Backup on test DB then updated Id's in New Column
Solutions 2: Update Id's From Other Relational table based on column mapping .
Upvotes: 0
Reputation: 11205
Use a CTE for an initial repopulation:
with CTE as
(
select t1.*, row_number() over (order by AnyColumn) as RN
from MyTable t1
)
update CTE
set ID = RN
Upvotes: 1