Select Into statement in SQL

Rumman Ansari   Software Engineer   2023-03-25   5592 Share
☰ Table of Contents

Table of Content:


The SELECT INTO statement copies data from one table into a new table.

Syntax:


SELECT *
INTO newtable [IN externaldb]
FROM oldtable
WHERE condition;

Copy only some columns into a new table:

Syntax:


SELECT column1, column2, column3, ...
INTO newtable [IN externaldb]
FROM oldtable
WHERE condition;

SQL SELECT INTO Examples

The following SQL statement creates a backup copy of Employee:


SELECT * INTO EmployeeBackup1
FROM Employee;

The following SQL statement uses the IN clause to copy the table into a new table in another database:


SELECT * INTO EmployeeBackup1 IN 'Backup.mdb'
FROM Customers;

The following SQL statement copies only a few columns into a new table:


SELECT EmployeeName, ContactName INTO EmployeeBackup1
FROM Employee;