2

How to add auto incrementing property to primary key of a table in Sql Server 2005 ? I have ProductID as primary key. I want to increment its value by 1 everytime a record is added. I didn't use IDENTITY keyword while creating table.

Bridge
  • 28,792
  • 9
  • 58
  • 81
Mudassir Hasan
  • 26,910
  • 19
  • 95
  • 126
  • check this out maybe helpfull http://stackoverflow.com/questions/958120/how-can-i-make-a-primary-key-as-autoincrement – Afshin Sep 20 '12 at 07:07
  • I think this will help: [Adding an identity to an existing column](http://stackoverflow.com/questions/1049210/adding-an-identity-to-an-existing-column) – valex Sep 20 '12 at 07:09

2 Answers2

2

There is a lot posted about this either here in SO or in other places. What you are looking for is exactly this

how to set auto increment after creating a table without any data loss?

Community
  • 1
  • 1
Yaroslav
  • 6,317
  • 10
  • 47
  • 87
2

Thank you everyone . i have found another way of adding IDENTITY property without sql commands.

In SQL Server Management console , go to Object Explorer->Select your Database->Select your Table->Right click on the Column on which Identity property has to be specified->Choose Modify option. In column Poperties window , scroll to Identity Specification . Change value of IsIdentity to Yes and specify seed and increment values and save.

Mudassir Hasan
  • 26,910
  • 19
  • 95
  • 126