Adding Identity to existing column with data in Sql Server -


this question has answer here:

i have table 4 million records. want change orderid identity without losing data.

is possible?

assuming orderid have no duplicates, 1. can create new table orderid identity column , copy data. drop existing table 2. create new identity column , drop existing orderid column

alter table (yourtable) add newcolumn int identity(1,1)     alter table (yourtable) drop column orderid  sp_rename 'yourtable.newcolumn', 'orderid', 'column' 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -