Quantcast
Viewing all articles
Browse latest Browse all 48

Adding an Identity Column to an Existing Table Sql Server

I want to add a column to an existing legacy database and write a procedure by which I can assign each record a different value. Something like add a column and autogenerate the data for it.

Like, if I add a new column called “ID” (number) I want to then initialize a unique value to each of the records. So, my ID column will have records from say 1 to 1000. How do I do that?

Solution

This will depend on the database but for SQL Server, this could be achieved as follows:

alter table Example
add NewColumn int identity(1,1)

The post Adding an Identity Column to an Existing Table Sql Server appeared first on Solved.


Viewing all articles
Browse latest Browse all 48

Trending Articles