Insert values to identity column in SQL Server

Introduction

In a SQL server Table if you define a column as an identity column and if you try to insert value in this column then you will get an error message:

Below I have an Employee Table and ID column is identity here.

test db

Now write an Insert query like below.

dbo.employee

To insert Set IDENTITY_INSERT to ON

  1. SET IDENTITY_INSERT Employee ON  
image3 database

If you set IDENTITY_INSERT OFF then use below inserts statement to insert records.

set identity

You don’t need to write IDENTITY_INSERT OFF.

dboemploye
 

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now