Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why am I not able to insert values into a table?

I have a database called Music and a table called Genre. I have written the following code:

USE Music

INSERT INTO Genre (GenreID, Genre)
VALUES 
  (1,'Rock'),
  (2,'Jazz'), 
  (3,'Country'),
  (4,'Pop'),
  (5,'Blues'),
  (6,'Hip-Hop'),
  (7,'Rap'),
  (8,'Punk');

I am getting the following error:

Msg 544, Level 16, State 1, Line 3
Cannot insert explicit value for identity column in table ‘Genre’ when IDENTITY_INSERT is set to OFF.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any ideas why this is?

>Solution :

you can add this to your code

SET IDENTITY_INSERT Genre ON
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading