我试图在表中插入哪个标识为真并得到错误 [英] Iam trying to insert in the table which identity is true and getting the error

查看:82
本文介绍了我试图在表中插入哪个标识为真并得到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

插入GPS_Vouchers值('10 / 25/2018 12:00:00 AM','Issuer Inter switch WDRL Txn',12,'HBL',35,'CUP','cupISS123 ','SBP-HBL',21,035.56)




表中的
标识为真,我收到此错误。



这是错误表'GPS_Vouchers'中的标识列的显式值只能在使用列列表且IDENTITY_INSERT为ON时指定。 / pre> 



我的尝试:



i尝试身份确认并仍然收到此错误



这是错误只能指定表'GPS_Vouchers'中标识列的显式值当使用列列表并且IDENTITY_INSERT为ON时

解决方案

简单:始终为列命名。

At你要去的那一刻:

  INSERT   INTO  MyTable  VALUES  1  2 

只有在表中有两列且您知道顺序时才有效,因为SQL假定要从最左侧列开始插入值并向右移动。

但你没有,你有三列:

 ID INT,IDENTITY 
Ones INT
Twoes INT

SO SQL正在尝试将您提供的第一个值插入最左侧列 - ID - 并正确地抱怨您无法设置IDENTITY列的值,因为这是它的工作。

所以总是添加列名:

  INSERT   INTO  MyTable(Ones,Twoes) VALUES  1 ,< span class =code-digit> 2 )

您的问题将消失,未来对表格的更改不会弄乱您的数据。


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

解决方案

Simple: always name your columns.
At the moment you are going:

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:

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.


这篇关于我试图在表中插入哪个标识为真并得到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆