SELECT INTO creates a new table and populates it with the result of a SELECT query in database systems that support this syntax.
It provides a convenient way to create a new table from existing data for temporary analysis, backups, transformations, or staging.
An analyst can create a table containing only employees from the Finance department.
SELECT
EmployeeID,
EmployeeName,
Salary
INTO FinanceEmployees
FROM Employees
WHERE Department = 'Finance';
SELECT INTO is often used in SQL Server and some other database systems for temporary tables, data preparation, and copying selected data.
- SELECT INTO can create a new table.
- The query result populates the new table.
- The destination table generally must not already exist.
- It is useful for copying selected data.
- Syntax and behavior vary by database.
What does SELECT INTO do?
SELECT INTO creates a new table and populates it with the result of a SELECT query where supported.
How is SELECT INTO different from INSERT SELECT?
SELECT INTO creates a new destination table, while INSERT SELECT inserts data into an existing table.