SQL SELECT INTO Statement

## SQL Basic

SQL HOME SQL Intro SQL Syntax SQL SELECT SQL SELECT DISTINCT SQL WHERE SQL AND & OR SQL ORDER BY SQL INSERT INTO SQL UPDATE SQL DELETE SQL Injection

## SQL Advanced

SQL SELECT TOP SQL LIKE SQL Wildcards SQL IN SQL BETWEEN SQL Aliases SQL Joins SQL INNER JOIN SQL LEFT JOIN SQL RIGHT JOIN SQL FULL JOIN SQL UNION SQL SELECT INTO SQL INSERT INTO SELECT SQL CREATE DB SQL CREATE TABLE SQL Constraints SQL NOT NULL SQL UNIQUE SQL PRIMARY KEY SQL FOREIGN KEY SQL CHECK SQL DEFAULT SQL CREATE INDEX SQL DROP SQL ALTER SQL Auto Increment SQL Views SQL Dates SQL NULL Values SQL NULL Functions SQL General Data Types SQL DB Data Types

## SQL Functions

SQL Functions SQL AVG() SQL COUNT() SQL FIRST() SQL LAST() SQL MAX() SQL MIN() SQL SUM() SQL GROUP BY SQL HAVING SQL UCASE() SQL LCASE() SQL MID() SQL LEN() SQL ROUND() SQL NOW() SQL FORMAT()
SQL Quick Ref SQL Hosting SQL Summary

## SQL Quiz

SQL Quiz

# SQL SELECT INTO Statement

« Previous
Next Chapter »

With SQL, you can copy information from one table into another.

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

## The SQL SELECT INTO Statement

The SELECT INTO statement selects data from one table and inserts it into a new table.

### SQL SELECT INTO Syntax

We can copy all columns into the new table:

SELECT *
INTO newtable [IN externaldb]
FROM table1;

Or we can copy only the columns we want into the new table:

SELECT column_name(s)
INTO newtable [IN externaldb]
FROM table1;

| Tip: The new table will be created with the column-names and types as defined in the SELECT statement. You can apply new names using the AS clause.

## SQL SELECT INTO Examples

Create a backup copy of Customers:

SELECT *
INTO CustomersBackup2013
FROM Customers;

Use the IN clause to copy the table into another database:

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

Copy only a few columns into the new table:

SELECT CustomerName, ContactName
INTO CustomersBackup2013
FROM Customers;

Copy only the German customers into the new table:

SELECT *
INTO CustomersBackup2013
FROM Customers
WHERE Country='Germany';

Copy data from more than one table into the new table:

SELECT Customers.CustomerName, Orders.OrderID
INTO CustomersOrderBackup2013
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID;

Tip: The SELECT INTO statement can also be used to create a new, empty table using the schema of another. Just add a WHERE clause that causes the query to return no data:

SELECT *
INTO newtable
FROM table1
WHERE 1=0;
« Previous
Next Chapter »

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE