我该如何处理这个错误 [英] How Do I Handle This Error
问题描述
如何处理此错误(只有在使用列列表且IDENTITY_INSERT为ON时才能指定表'约会'中标识列的显式值。)
你的桌子[约会]上有一列已被定义为IDENTITY但在你的代码中你试图为它分配一个显式值。
不要 - IDENTITY列的重点是数据库会为你生成这些值。
例如:
创建 表演示
(
myID int IDENTITY ( 1 , 1 ),
otherData varchar ( 30 )
)如果我尝试使用此数据将数据放入该表中pre lang =sql> insert into Demo values
( 1 ,' first datum'),
( 2 ,' second datum'),
( 3 ,' < span class =code-string> third datum')然后我会收到错误报告
Quote:消息8101,级别16,状态1,行1
只有在使用列列表且IDENTITY_INSERT为ON时,才能指定表'演示'中标识列的显式值。 / blockquote>相反,我需要使用insert 进入 Demo values
(' 第一个数据'),
(' 第二个数据'),
(' 第三个数据')然后当我选择时我得到
myId otherData
1第一个数据
2秒数据
3个第三个数据
how can i handle this error ("An explicit value for the identity column in table 'appointment' can only be specified when a column list is used and IDENTITY_INSERT is ON.")
解决方案You have a column on your table [appointment] which has been defined as IDENTITY but in your code you are attempting to assign an explicit value to it.
Don't - the whole point of IDENTITY columns is that the database will generate those values for you.
An example:
create table Demo ( myID int IDENTITY(1,1), otherData varchar(30) )If I attempt to put data into that table using this
insert into Demo values (1,'first datum'), (2,'second datum'), (3,'third datum')then I will get an error reported
Quote:Msg 8101, Level 16, State 1, Line 1
An explicit value for the identity column in table 'Demo' can only be specified when a column list is used and IDENTITY_INSERT is ON.Instead, I need to use
insert into Demo values ('first datum'), ('second datum'), ('third datum')then when I select I get
myId otherData 1 first datum 2 second datum 3 third datum
这篇关于我该如何处理这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!