SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 change a varchar column to int identity(1,1)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

learning_grsql
Posting Yak Master

230 Posts

Posted - 01/28/2013 :  03:44:00  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2208 Posts

Posted - 01/28/2013 :  04:02:40  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 01/28/2013 :  04:05:50  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000