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

How to set identity_insert to on in SQL Server?

Asked by Caroline Brown Jul 19, 2021 2.6K views 1 answer
Share

About this question

 I get the command set identity_insert table_name on;, but for some reason it is not actually changing the attribute. I've done it with the account that I created the table with, and I've also created an 'admin' account and gave it permissions to do anything (to the best of my knowledge). Whenever I run the command under either account I get the result of '0 rows affected', then I am unable to run the query to insert the rows I wish to insert with the following error: Cannot insert explicit value for identity column in table 'table_name' when IDENTITY_INSERT is set to OFF. Additionally I've tried to include the schema name in the query like:

set identity_insert mySchema.table_name on;
but I get the following error:
Cannot find the object "mySchema.table_name" because it does not exist or you do not have permissions.
Also of note, my project looks like:
localhostSQLEXPRESS -Databases --System Databases --mySchema

Does anyone know a solution to this problem?

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.