The IDENTITY function cannot be used with a SELECT INTO statement containing a UNION, INTERSECT or EXCEPT operator.

Error Message:
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.

Severity level:
15.

Description:
This error message appears when in a SELECT INTO statement that involves a UNION, INTERSECT, or EXCEPT operator, the IDENTITY function shall be used.

Consequences:
The SQL statement cannot be parsed and further execution is stopped.

Resolution:
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.

Versions:
All versions of SQL Server.

Example(s):
IF OBJECT_ID (‘dbo.T’) IS NOT NULL
    DROP TABLE dbo.T
SELECT
    IDENTITY(int, 1,1) AS ID_Num
INTO
    dbo.T
FROM
    (SELECT 1) X
UNION ALL
SELECT
    2

Remarks:
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.




Related Articles :

  • No Related Articles Found

Trackbacks/Pingbacks

  1. SQL Server Performance - May 22, 2011

    [...] [...]

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |