The SQL SELECT INTO Statement: A Comprehensive Guide

Rumman Ansari   Software Engineer   2024-07-18 09:44:18   5910  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

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;



Stay Ahead of the Curve! Check out these trending topics and sharpen your skills.