sql - Inserting a new column for serial number -


i have table 500 records in , want insert new column "serial number" starting 1.

if care order in identity values assigned, best off doing this:

create table dbo.newtable (   serialnumber int identity(1,1),   ... other columns original table ... );  insert dbo.newtable(...other columns...)   select ...other columns...   dbo.originaltable   order ...ordering criteria...   option (maxdop 1); -- prevent parallelism messing identity  drop table dbo.originaltable;  exec sp_rename n'dbo.newtable', n'originaltable', n'object'; 

you may have deal constraints etc. , want in transaction. point adding identity column table assign identity values in arbitrary order. if don't care how existing values assigned serial numbers, use kyle's answer.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -