Link to home
Create AccountLog in
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
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

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


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
Avatar of mribasu
mribasu
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of mkobrin
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.
Avatar of Spike

ASKER

Worked- although how do you do it through the table design properties?
Avatar of 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.