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
 altering table to add identity column

Author  Topic 

anjali66
Starting Member

23 Posts

Posted - 2011-01-07 : 18:02:29
is their any way, I can add identity column in an already existing table?

Please help

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-01-07 : 18:09:26
ALTER TABLE myTable ADD newColumn int NOT NULL IDENTITY(1,1)
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2011-01-07 : 23:57:30
do you want to add a new identity column or else want to add identity property to a existing column.
if you want to add a new identity column robvolk has given the solution.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-08 : 01:02:28
you cant directly change identity property of existing column . for that you need something like

http://www.mssqltips.com/tip.asp?tip=1397

if you just want to add a new column of type identity the above solution is enough

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

Go to Top of Page

anjali66
Starting Member

23 Posts

Posted - 2011-01-08 : 10:01:47
Thanks Visakh and RobVolk.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-08 : 13:01:40
welcome

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

Go to Top of Page
   

- Advertisement -