SQL: Adding Identity Column to Existing Table

In MS SQL Server run the following query and an auto-generated identity column will be added to an existing table with existing data and each row will be automatically assigned an Integer in the new column.

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s