DF001: The SELECT…INTO statement is used to create a table.
Last modified: May 28, 2025
The topic describes the DF001 T-SQL code analysis rule.
Category
BEST PRACTICE
Message
The SELECT…INTO statement is used to create a table.
Description
It is not recommended to use the SELECT…INTO statement to create a table. Instead, create the table manually using the CREATE TABLE statement.
Additional information
The SELECT…INTO statement first creates a new table and then inserts rows into it. If the insertion operation fails or encounters an error, the inserted rows will be undone, and as a result, the new table will remain empty. If you want the entire operation to succeed or fail as a whole, consider using an explicit transaction.
Noncompliant code example
SELECT FirstName, LastName INTO #Customers FROM dbo.Customers
Compliant solution
CREATE TABLE #Customers(FirstName nvarchar(128), LastName nvarchar(128))
INSERT INTO #Customers (FirstName, LastName)
SELECT FirstName, LastName FROM dbo.Customers
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.