SELECT INTO combines table creation and data population. When executed, the database engine creates a new table with the specified name, defines columns matching the data types of the selected expressions, and immediately inserts the query result set. Existing tables with the same name cause an error unless the dialect supports IF NOT EXISTS. Constraints, indexes, triggers, and identity properties are not copied unless explicitly handled afterward. In SQL Server and PostgreSQL, SELECT INTO is optimized for large bulk loads and runs as a minimally logged operation inside simple recovery models. Oracle and MySQL do not support SELECT INTO for creating tables; they use CREATE TABLE AS SELECT (CTAS) instead. In PL-SQL, SELECT INTO assigns query results to variables, which is unrelated to the table-creating form discussed here.
column_list
(list) - One or more columns or expressions to copy.new_table_name
(identifier) - Name of the table to create. Can be a regular, temporary, or external table depending on prefix.source_table
(identifier) - Table or view supplying the data.IN database_name
(identifier) - (PostgreSQL only) Store the new table in another database.WHERE / JOIN / GROUP BY
(clauses) - Same behavior as in a normal SELECT.CREATE TABLE AS, INSERT INTO SELECT, SELECT, Temporary Tables, CTAS
Microsoft SQL Server 6.0 (1995)
No. The statement fails with an error if the target table name already exists. Drop or rename the table first.
Execute ALTER TABLE or CREATE INDEX statements on the new table once data is loaded.
MySQL reserves SELECT INTO for variable assignment in stored programs. Use CREATE TABLE new_table AS SELECT ... instead.
Yes. Any valid SELECT clauses (JOIN, WHERE, GROUP BY, HAVING, ORDER BY) may appear. ORDER BY is ignored for the physical storage order.