Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to create id column in existing table

Author  Topic 

learning_grsql
Posting Yak Master

230 Posts

Posted - 2012-08-14 : 02:42:24
I import data from excel into a table in sql server management 2008 studio database using import and export wizard.

The table doesn't have any autonumber field. I want to add a column named "id" and it should produce numbers with autoincrement 1 and starting value should be 1.

Is it possible?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-08-14 : 02:45:36
[code]alter table <table name> add id int identity(1,1)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-14 : 10:28:24
quote:
Originally posted by learning_grsql

I import data from excel into a table in sql server management 2008 studio database using import and export wizard.

The table doesn't have any autonumber field. I want to add a column named "id" and it should produce numbers with autoincrement 1 and starting value should be 1.

Is it possible?


you can do it during package creation itself if its a new table. just click on sql for create table and manually add identity column in CREATE TABLE statement
if its already created use Tans suggestion

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -