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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
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)
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

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

Flowing Fount of Yak Knowledge

2242 Posts

Posted - 01/28/2013 :  04:02:40  Show Profile  Reply with Quote
Check this link.. there are two methods to achieve this alteration...

Go to Top of Page

Very Important crosS Applying yaK Herder

52326 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

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000