@manhng

Welcome to my blog!

How to alter column to identity (1,1)

May 7, 2019 23:51

How to alter column to identity (1, 1) (edit)

https://stackoverflow.com/questions/1049210/adding-an-identity-to-an-existing-column

CREATE TABLE dbo.Tmp_CropType
(
[Id] INT PRIMARY KEY NOT NULL IDENTITY (1, 1),
[Name] NVARCHAR(255) NULL
) ON [PRIMARY]

go
SET IDENTITY_INSERT dbo.Tmp_CropType ON
IF EXISTS(SELECT * FROM dbo.CropType)
INSERT INTO dbo.Tmp_CropType ([Id], [Name])
SELECT [Id], [Name] FROM dbo.CropType TABLOCKX
SET IDENTITY_INSERT dbo.Tmp_CropType OFF
DROP TABLE dbo.CropType
EXEC sp_rename 'Tmp_CropType', 'CropType'

Categories

Recent posts