DEFAULT or NULL are not allowed as explicit identity values.

Normally, an IDENTITY column can not be a Nullable.

When we try to insert some explicit data into an IDENTITY column the following error occurred.

Create Table Tb_Table1
(
Id Int Identity(1,1),
Column1 int
)
Go

Set identity_insert Tb_Table1 on
Insert Tb_Table1 (Id,Column1) values(Null,1)
Set identity_insert Tb_Table1 off


It'll throw an error
Msg 339, Level 16, State 1, Line 2
DEFAULT or NULL are not allowed as explicit identity values.

No comments:

Post a Comment