1

It is possible to alter existing MSSQL column to add auto increment option to this column (it is primary key, but not auto increment) without writing t-sql code, but just with alter stratements?

I can find solution with t-sql, but I need without it.

3
  • Can I ask why you don't want to use T-SQL? If you have ways of solving a problem, why not use them? Commented Sep 25, 2013 at 18:07
  • 5
    How are alter statements not T-SQL? Commented Sep 25, 2013 at 18:15
  • when you say not using t-sql do you mean using sql-92? and no t-sql specific commands? Commented Sep 25, 2013 at 18:32

1 Answer 1

6

according to this link http://social.msdn.microsoft.com/Forums/sqlserver/en-US/04d69ee6-d4f5-4f8f-a115-d89f7bcbc032/how-to-alter-column-to-identity11 "You can't alter the existing columns for identity." It provides a couple of possible solutions. Relevant commands are:

alter table YourTable drop column OldId alter table YourTable add NewId int identity(1,1) 
Sign up to request clarification or add additional context in comments.

2 Comments

simple way to do the above suggested: go to the table on ms sql management studio. right click on the table > script table as > drop and create to > new query editor window edit and add the identity where needed and run the whole sql
if you have data too, right click on your database in sql management studio > tasks > generate scripts. in choose object section, select "select specific database objects" and select your table(s) you want to alter and click next. on "set scripting options" section, choose "save to new query window" and click on advanced. in the advanced window, under "script drop and create", select "script drop and create" and under "types of data to script" select "Schema and data". click ok and proceed. you can then run the created queries.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.