The SELECT INTO statement in SQL is a powerful and efficient command that allow users to create a new table and populate it with data from an existing table or query result in a single step. This feature is especially useful for creating backups, extracting specific subsets of data.
🡆Creates a new table with the same schema and data types as the source table.
🡆Copies selected rows and columns based on conditions (optional).
🡆Eliminates the need to manually create the target table before inserting data
SELECT column1, column2…
INTO new_table
FROM source_table
WHERE condition;
To create a new table CustomerNames containing only the CustomerID and CustomerName from the Customers table:
SELECT *
INTO CustomersBackup
FROM Customers;