The IDENTITY_INSERT of the table'material.dbo.xxxxx' is already ON. Cannot perform SET operation on table'xxxxx'.

When inserting data into a table,

If automatic numbering is inserted, an error may be displayed:

When IDENTITY_INSERT is set to OFF, you cannot insert an explicit value into the identity column in the table'xxx'.

I did the set identity_insert PCBASettingList ON operation before inserting into a table

Suddenly found:

"The IDENTITY_INSERT of table'material.dbo.xxxxx' is already ON. SET operation cannot be performed on table'xxxxx'."

But obviously only one set on operation was performed in the code

Then I thought that when I first copied this set statement, I just started the set statement to execute other tables.

Then I saw an article:

SQL Server self-increase column inserts the specified value - SET IDENTITY_INSERT ON|OFF

Suddenly, the specific parts are as follows:

.建立另外一个表products2,尝试相同插入操作:
CREATE TABLE products2 (id int IDENTITY PRIMARY KEY, product varchar(40))

然后执行:
SET IDENTITY_INSERT products2 ON
INSERT INTO products2 (id, product) VALUES(1, 'garden shovel')

导致错误:“表 'material.dbo.products' 的 IDENTITY_INSERT 已经为 ON。无法对表 'products2' 执行 SET 操作。”

改为执行:
SET IDENTITY_INSERT products OFF
SET IDENTITY_INSERT products2 ON
INSERT INTO products2 (id, product) VALUES(2, 'garden shovel')

So first set the table that was originally set to ON, first set it to off, and then set the other table to ON.

that's it

Guess you like

Origin blog.csdn.net/yangkunhenry/article/details/100532316