Msg 1057, Level 15, State 5, Line 11
The IDENTITY function cannot be used with a SELECT INTO statement containing a UNION, INTERSECT or EXCEPT operator.
This error message appears when in a SELECT INTO statement that involves a UNION, INTERSECT, or EXCEPT operator, the IDENTITY function shall be used.
The SQL statement cannot be parsed and further execution is stopped.
Errors of the Severity Level 15 are generated by the user and can be fixed by the SQL Server user. The statement cannot be executed this way. You cannot use the IDENTITY function in such a SELECT INTO statement.
All versions of SQL Server.
IF OBJECT_ID (‘dbo.T’) IS NOT NULL
DROP TABLE dbo.T
IDENTITY(int, 1,1) AS ID_Num
(SELECT 1) X
In the above example we try to use the IDENTITY function in a SELECT INTO statement that contains a UNION operator. This raises the error.