The topic describes the DF001 T-SQL code analysis rule.
BEST PRACTICE
The SELECT…INTO statement is used to create a table.
It is not recommended to use the SELECT…INTO statement to create a table. Instead, create the table manually using the CREATE TABLE statement.
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.
SELECT FirstName, LastName INTO #Customers FROM dbo.Customers
CREATE TABLE #Customers(FirstName nvarchar(128), LastName nvarchar(128))
INSERT INTO #Customers (FirstName, LastName)
SELECT FirstName, LastName FROM dbo.Customers