Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change column to an autoincrement field

Status
Not open for further replies.

j252ewv

Programmer
Jul 2, 2008
43
GB
I have a table which has a primary key,this key although numeric is not auto increment but is unique, I need to convert this column to an autoincrement field, can some ome help me with the tsql to achieve this.

 
You need to calculate the max of the number, create a new column with identity field starting from Max+1

insert data from your original table into this new one using

SET IDENTITY_INSERT ON -- check syntax in BOL

and after everything is done, you can delete your original table and rename the new one to the old.



PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top