I have a table with huge amount of data. I’d like to add extra column id and use it as a primary key. What is the better way to fill this column with values from one 1 to row count
Currently I’m using cursor and updating rows one by one. It takes hours. Is there a way to do that quicker?
Thank you
Just do it like this:
and the column will be created and automatically populated with the
integervalues (as Aaron Bertrand points out in his comment – you don’t have any control over which row gets what value – SQL Server handles that on its own and you cannot influence it. But all rows will get a validintvalue – there won’t be anyNULLor duplicate values).Next, set it as primary key: