Link to home
Create AccountLog in
Avatar of vbnetcoder
vbnetcoder

asked on

i have a primary key field -- but how do i update the field so that it is is an identity column that increments by one every time something is inserted

i have a primary key field -- but how do i update the field so that it is is an identity column that increments by one every time something is inserted.

It is an existing table so i believe I have to use alter table but not sure of all the syntax
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

You want to update an identity column? Be careful with updating a primary key column since it can affect the referential integrity. You'll need first to disable the constraint before updating the field.
Avatar of vbnetcoder
vbnetcoder

ASKER

This is a test database so not a huge deal
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Assuming this would work you could change a column to identity only if its data type is int/bigint however I think the SSMS change will not work and it will generate an error when you will hit the save button.
ty