DF001: The SELECT…INTO statement is used to create a table.

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

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?