You are on page 1of 8

3/23/2020 SQL SELECT INTO Statement

  HTML CSS MORE   


w3schools.com

View PDF OPEN


File Size: 2.00MB. OS: Win/MacOS

SQL SELECT INTO Statement


❮ Previous Next ❯

The SQL SELECT INTO Statement


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

SELECT INTO Syntax


Copy all columns into a new table:

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

Copy only some columns into a new table:

SELECT column1, column2, column3, ...


INTO newtable [IN externaldb]
FROM oldtable
WHERE condition;

https://www.w3schools.com/sql/sql_select_into.asp 1/8
3/23/2020 SQL SELECT INTO Statement

  HTML CSS MORE   


The new table will be created with the column-names and types as defined in the old
table. You can create new column names using the AS clause.

SQL SELECT INTO Examples


The following SQL statement creates a backup copy of Customers:

SELECT * INTO CustomersBackup2017


FROM Customers;

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

SELECT * INTO CustomersBackup2017 IN 'Backup.mdb'


FROM Customers;

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

SELECT CustomerName, ContactName INTO CustomersBackup2017


FROM Customers;

The following SQL statement copies only the German customers into a new table:

SELECT * INTO CustomersGermany


FROM Customers
WHERE Country = 'Germany';

The following SQL statement copies data from more than one table into a new table:
https://www.w3schools.com/sql/sql_select_into.asp 2/8
3/23/2020 SQL SELECT INTO Statement

  HTML CSS MORE   


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

Tip: SELECT INTO 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 oldtable
WHERE 1 = 0;

❮ Previous Next ❯

https://www.w3schools.com/sql/sql_select_into.asp 3/8
3/23/2020 SQL SELECT INTO Statement

  HTML CSS MORE   

COLOR PICKER

HOW TO

Tabs
Dropdowns
Accordions
Side Navigation
Top Navigation

https://www.w3schools.com/sql/sql_select_into.asp 4/8
3/23/2020 SQL SELECT INTO Statement

Modal Boxes
  HTML CSS MORE   
Progress Bars
Parallax
Login Form
HTML Includes
Google Maps
Range Sliders
Tooltips
Slideshow
Filter List
Sort List

SHARE

 

CERTIFICATES

HTML
CSS
JavaScript
SQL
Python
PHP
jQuery
Bootstrap
XML

Read More »

https://www.w3schools.com/sql/sql_select_into.asp 5/8
3/23/2020 SQL SELECT INTO Statement

  HTML CSS MORE   

Stop Using Toilet P


This “DIY” bathroom upgrade
saving Americans thousands
Toilet Paper.
ClearRear

https://www.w3schools.com/sql/sql_select_into.asp 6/8
3/23/2020 SQL SELECT INTO Statement

  HTML CSS MORE   

 
Sponsored

REPORT ERROR

PRINT PAGE

FORUM

ABOUT

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
jQuery Tutorial
Java Tutorial
C++ Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference

https://www.w3schools.com/sql/sql_select_into.asp 7/8
3/23/2020 SQL SELECT INTO Statement

HTML Colors
  HTML CSS MORE jQuery Reference  
Java Reference
Angular Reference

Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
jQuery Examples
Java Examples
XML Examples

Web Certificates
HTML Certificate
CSS Certificate
JavaScript Certificate
SQL Certificate
Python Certificate
jQuery Certificate
PHP Certificate
Bootstrap Certificate
XML Certificate

Get Certified »

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading
and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our
terms of use, cookie and privacy policy. Copyright 1999-2020 by Refsnes Data. All Rights Reserved.
Powered by W3.CSS.

https://www.w3schools.com/sql/sql_select_into.asp 8/8

You might also like