The INTO keyword appears in two main contexts. In INSERT statements it specifies the target table that will receive new rows. In SELECT statements it can create a new table from the query result set (supported in SQL Server, PostgreSQL, and others). INSERT INTO adds data to an existing table, while SELECT INTO both defines and fills a new table in a single step. Because SELECT INTO implicitly creates the destination table, column definitions are derived from the result set’s data types. Transactional rules of the surrounding session apply: the operation can be committed or rolled back. Permissions are required on the source tables and on the target schema for table creation or modification. Some systems, notably MySQL and SQLite, do not support SELECT INTO; they use CREATE TABLE … AS instead. Using INTO within stored procedures can simplify ETL staging tables, but be mindful of tempdb usage and naming collisions. Always check that the destination table does not already exist, or use TEMPORARY keywords where supported to avoid runtime errors.
target_table
(identifier) - Existing table that will receive rows when using INSERT INTO.new_table
(identifier) - Name of the table to be created when using SELECT INTO.column_list
(list) - Optional explicit list of columns in the destination table for INSERT INTO.values_list
(list) - Literal values or expressions to insert.select_list
(list) - Columns or expressions produced by the SELECT query.source_table
(identifier) - Table(s) queried to supply data.INSERT, SELECT, CREATE TABLE AS, VALUES clause, WITH (CTE), ROLLBACK, COMMIT
SQL-92 (INSERT INTO). SELECT INTO popularized in early Sybase/SQL Server and adopted by PostgreSQL.
INSERT INTO appends rows to an existing table, while SELECT INTO creates a new table and fills it in one step.
No. The statement fails if the target table name already exists in most systems. Use INSERT INTO or DROP TABLE first if you need to replace it.
Not entirely. Although INSERT INTO is standardized, SELECT INTO is proprietary to several dialects. For portable code use CREATE TABLE ... AS SELECT instead.
Batch the inserts, disable non-essential indexes or constraints temporarily, and use bulk-load utilities where available.