Error Message:
Msg 339, Level 16, State 1, Line 2
DEFAULT or NULL are not allowed as explicit identity values.
Severity level:
16.
Description:
This error message appears, when one tries to explicitely INSERT a NULL marker into a column with the IDENTITY property. The same error is raised, when one tries to enter a value into such an IDENTITY column by using the DEFAULT VALUES syntax.
Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.
Resolution:
Error of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. Neither NULL nor DEFAULT VALUES can be used to insert a value into a column with the IDENTITY property.
Versions:
This error message was introduced with SQL Server 2005.
Example(s):
USE tempDB
GO
CREATE TABLE t
(
i1 INT IDENTITY
)
GO
SET IDENTITY_INSERT t ON
INSERT INTO t(i1) SELECT NULL
DROP TABLE t
GO
Remarks:
When you try to insert a value into a column with the IDENTITY property via SET IDENTITY_INSERT, this value should be of an integer type or the expression should evaluate to an integer type.