SQL Server SELECT INTO Guide

The SELECT INTO statement can insert the result set of a query into a new table. The syntax is as follows:

SELECT column1, column2, ...
INTO new_table
FROM source_table
WHERE condition;

Where column1, column2, … represent the columns to be selected, new_table is the new table name, source_table is the source table for the query, and condition is the filtering condition.

For example, select columns A and B from table A and insert the results into a new table B.

SELECT A, B
INTO tableB
FROM tableA;

Note: When using the SELECT INTO statement, the new table B must not exist, otherwise it will result in an error. If you want to insert the results into an existing table, you can use the INSERT INTO statement.

bannerAds