Troubleshooting Guide: Error 2770 — SELECT INTO Statement Cannot Have Same Source and Destination Tables
Why This Error Happens
This error occurs when a SELECT INTO statement references the same table name for both the source data and the newly created destination table, which SQL Server explicitly disallows because the destination table must not exist prior to execution. It commonly happens when scripts are copy-pasted across environments without updating table names, or when dynamic SQL generates identical source/target identifiers due to a logic error in variable substitution. It can also surface when a three-part or four-part naming convention (database.schema.table) resolves to the same physical object despite differing syntax.
Step-by-Step Resolution Guide
Step 1: Review and Identify the Conflicting Table Names
- Open the query in SQL Server Management Studio (SSMS) or Azure Data Studio and locate the exact
SELECT ... INTOstatement. - Check both the
INTOclause and theFROMclause to confirm if they reference the identical table, including matching database and schema prefixes (e.g.,dbo.SalesDatavsSalesDatamay resolve to the same object). - Run
sp_help 'TableName'to confirm the actual object being referenced if synonyms or views are involved.
Step 2: Rename the Destination Table or Use a Temporary Table
- Modify the
INTOclause to point to a new, uniquely named table, such asSalesData_Archiveor a staging table like#TempSalesData. - Example corrected syntax:
SELECT * INTO dbo.SalesData_Backup FROM dbo.SalesData;
- If the intent was to duplicate data within the same table structure, consider using
INSERT INTO ... SELECTinstead, which supports self-referencing operations under proper conditions.
Step 3: Audit Dynamic SQL and Stored Procedures
- If the statement is generated dynamically (e.g., via
EXEC sp_executesql), inspect the parameter values being concatenated into the source and destination variables. - Check for missing or incorrect suffixes/prefixes in variable naming logic (e.g., a loop variable failing to increment a table name counter).
- Add temporary
PRINTstatements before execution to output the generated SQL string and visually confirm the source and destination differ.
Step 4: Validate Linked Server or Cross-Database References
- If the query spans linked servers or multiple databases, ensure the four-part naming convention (
Server.Database.Schema.Table) is fully qualified and distinct for both source and destination. - Confirm there is no synonym or view aliasing that causes two differently named objects to resolve to the same underlying table.
Alternative or Verification Steps
- Re-run the corrected query in a non-production environment first and confirm the new destination table is created successfully with
SELECT * FROM sys.tables WHERE name = 'NewTableName';. - If the error persists despite differing names, check for case-insensitive collation settings or duplicate synonyms using
SELECT * FROM sys.synonyms;that might be silently redirecting both references to the same table.