Inserting a SQL Server IDENTITY
This is not the first time in this book that we have talked about inserting SQL Server IDENTITY
values, but let's consider this section a must-have for this chapter. The problem consists of the fact that SQL Server doesn't allow us to specify an explicit value for an IDENTITY
field as the PRODUCT
primary key:
CREATE TABLE [product] ( [product_id] BIGINT NOT NULL IDENTITY, ... );
In other words, the following INSERT
statement will cause the following error – Cannot insert explicit value for identity column in table 'product' when IDENTITY_INSERT is set to OFF:
ctx.insertInto(PRODUCT, PRODUCT.PRODUCT_ID, PRODUCT.PRODUCT_LINE, PRODUCT.CODE, PRODUCT.PRODUCT_NAME) .values(5555L, "Classic Cars"...