Monday, December 26, 2022

Create identity column when table is already created SQL

 ALTER TABLE [UserName] DROP COLUMN [ID];


ALTER TABLE [UserName] 
    ADD [ID] integer identity not null;

This will add the id column to last

or

drop the table and create table and add identity in id

CREATE TABLE [dbo].[OpenVacancy](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[CadreName] [varchar](100) NULL,
	[CadreID] [int] NULL,
	[InstituteName] [varchar](100) NULL,
	[InstituteID] [int] NULL,
	[DisciplineName] [varchar](100) NULL,
	[DisciplineID] [int] NULL,
	[SanctionedStrength] [int] NULL,
	[InPosition] [int] NULL,
	[Vacancy] [int] NULL,
	[OpenVacancy] [int] NULL,
 CONSTRAINT [PK_OpenVacancy] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

No comments:

Post a Comment