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
 change a varchar column to int identity(1,1)

Author  Topic 

learning_grsql
Posting Yak Master

230 Posts

Posted - 2013-01-28 : 03:44:00
I have a column with datatype varchar(20) and I would like to change the data type to int identity(1,1).

I tried the code below but it shows error near identity(1,1).


alter table mytable
alter column userid int identity(1,1) not null

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-01-28 : 04:02:40
Check this link.. there are two methods to achieve this alteration...

http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/04d69ee6-d4f5-4f8f-a115-d89f7bcbc032

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-28 : 04:05:50
you cant directly modify an existing column to be of type identity. you can use below workaround

http://www.mssqltips.com/sqlservertip/1397/add-or-drop-identity-property-for-an-existing-sql-server-column/

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

Go to Top of Page
   

- Advertisement -