Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

What to do if identity_insert is on?

Asked by Ranjana Admin Sep 30, 2022 1.5K views 1 answer
Share

About this question

How can I insert an ID into an identity column in SQL Server? I'll make a special item into my table and I will quickly detect that item by the ID. So because all other IDs are bigger or equal to one, I will give that special item the ID zero.


The problem is now, when I've created that table I've placed the identity of the column ID on true. If I insert now the special item with code below, I've got next error:


INSERT INTO MyTable(ID, Name, Description) 
VALUES (0, 'Special title', 'special item');
Error:
Cannot insert explicit value for identity column in table MyTable when IDENTITY_INSERT is set to OFF.

How can I change this table, column or property so I can create a record with ID zero?

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.