Click here to Skip to main content
15,887,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
insert into GPS_Vouchers values ('10/25/2018 12:00:00 AM','Issuer Inter switch WDRL Txn',12,'HBL',35, 'CUP','cupISS123','SBP-HBL',21,035.56)


in the table identity is true and i am getting this error.

this is the error An explicit value for the identity column in table 'GPS_Vouchers' can only be specified when a column list is used and IDENTITY_INSERT is ON.


What I have tried:

i tried identity true and still getting this error

this is the error An explicit value for the identity column in table 'GPS_Vouchers' can only be specified when a column list is used and IDENTITY_INSERT is ON
Posted
Updated 6-Mar-19 21:19pm

1 solution

Simple: always name your columns.
At the moment you are going:
SQL
INSERT INTO MyTable VALUES (1, 2)
which works only if you have two columns in your table and you know the order, because SQL assumes that the values are to be inserted starting with the "left most column" and movign right.
But you don't, you have three columns:
ID    INT, IDENTITY
Ones  INT
Twoes INT
SO SQL is trying to insert the first value you supplied into the "left most column" - ID - and rightly complaining that you can't set the value of an IDENTITY column because that is it's job.
So always add the columns names:
SQL
INSERT INTO MyTable (Ones, Twoes) VALUES (1, 2)
Your problem will go away, and future changes to the table won't mess up your data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900