Tuesday, October 22, 2019

How to alter column to identity(1,1)

u have 2 options,
1. Create a new table with identity & drop the existing table
2. Create a new column with identity & drop the existing column
Create table testtable(id int,name varchar(10))
insert into testtable values(1,'AAAAAA')
insert into testtable values(2,'BBBBB')
go
select * from testtable
go
Alter Table testtable Add Id_new Int Identity(1,1)

Go



Alter Table testtable Drop Column ID

Go



Exec sp_rename 'testtable.Id_new', 'ID','Column'

insert into testtable values('CCCC')


select * from testtable

================================================
connect to your db

show the table/column names in object explorer window

right click on column name

select modify

in column properties tab

   alter "identity specification"/"is identity" to YES

   set increment/seed properties as desired

No comments:

Post a Comment

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...