The SQL SELECT INTO statement can be used to select rows from one table and insert them into another. This is useful when you want to copy or create a backup of a table.
Employees Table
employeeID | employeeName |
1000 | John Smith |
1001 | Fred White |
1002 | Jane Scott |
1003 | Samuel Williams |
In this example, we will select records from the employees table and copy them to
the employees_bk table.
Syntax
SELECT *
INTO newTable
FROM oldTable
or
SELECT *
INTO newTable IN 'newDB.mdb'
FROM oldTable
or
SELECT tableName1.columnName1, tableName1.columnName2, etc...
INTO newTable
FROM oldTable
WHERE employeeID > 1002
or
SELECT tableName1.columnName1, tableName1.columnName2, etc...
INTO newTable
FROM oldTable
WHERE employeeID > 1002
|
Example
Make a copy of all fields in the employees table and insert them into the
employees_bk table.
SELECT *
INTO employees_bk
FROM employees |
Results
employeeID | employeeName |
1000 | John Smith |
1001 | Fred White |
1002 | Jane Scott |
1003 | Samuel Williams |
The SELECT INTO inserted the rows from the employees table into the employees_bk table.
Did you find the page informational and useful? Share it using one of your favorite social sites.
Recommended Books & Training Resources