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

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

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

Message par Clippy »

Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

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

Message par Clippy »

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

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

```
Répondre

Revenir à « SQL Server »