Avatar of Spike
Spike
 asked on

SQL Server Management Studio- setiing an Identity

I've created a table but want to add an identity column to it.
How is this done through the management studio? (SQL Server 2008)
(The Identity specification is disabled and set to No for all columns).
Cheers
Microsoft SQL ServerMicrosoft SQL Server 2008Microsoft Server Apps

Avatar of undefined
Last Comment
Guy Hengel [angelIII / a3]

8/22/2022 - Mon
sammySeltzer

ALTER TABLE YourTable ALTER COLUMN Id IDENTITY (200,1)


sammySeltzer

above assumes that the colum already exists.

If that isn't the case, then this will add a column and make it identity seed:

alter table yourTable
add  id int not null Identity(1,1)
ASKER CERTIFIED SOLUTION
mribasu

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mkobrin

If the column you want to use already has data in it you will not be able to use it as an Identity column, you will need to create a new column, and it will have to be an int column and it may not allow nulls.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Spike

ASKER
Worked- although how do you do it through the table design properties?
Guy Hengel [angelIII / a3]

you cannot ALTER a column to change from non-identity to identity.

you have to drop and recreate the column for that.