Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

sql - 当IDENTITY_INSERT设置为OFF时,无法为表'table'中的标识列插入显式值(Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF)

I have the below error when I execute the following script.

(执行以下脚本时出现以下错误。)

What is the error about, and how it can be resolved?

(错误是什么,如何解决?)

Insert table(OperationID,OpDescription,FilterID)
values (20,'Hierachy Update',1)

Error:

(错误:)

Server: Msg 544, Level 16, State 1, Line 1

(服务器:消息544,级别16,状态1,第1行)

Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF.

(当IDENTITY_INSERT设置为OFF时,无法在表'table'中为标识列插入显式值。)

  ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're inserting values for OperationId that is an identity column.

(您要为作为标识列的 OperationId插入值)

You can turn on identity insert on the table like this so that you can specify your own identity values.

(您可以像这样在表上打开标识插入,以便可以指定自己的标识值。)

SET IDENTITY_INSERT Table1 ON

INSERT INTO Table1
/*Note the column list is REQUIRED here, not optional*/
            (OperationID,
             OpDescription,
             FilterID)
VALUES      (20,
             'Hierachy Update',
             1)

SET IDENTITY_INSERT Table1 OFF 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...