I have a table with 4 million records. I want to change orderid to Identity without losing the data.
Is it possible?
I have a table with 4 million records. I want to change orderid to Identity without losing the data.
Is it possible?
Assuming orderid have no duplicates, 1. You can create a new table with orderid as identity column and copy the data. Then drop the existing table 2. Create a new identity column and drop the existing orderid column
ALTER TABLE (yourTable) ADD NewColumn INT IDENTITY(1,1)
ALTER TABLE (yourTable) DROP COLUMN orderid
sp_rename 'yourTable.NewColumn', 'orderid', 'COLUMN'