WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL SELECT INTO Statement


With SQL, you can duplicate data from one table into another.

The SELECT INTO explanation duplicates information from one table and embeds it into another table.


The SQL SELECT INTO Statement

The SELECT INTO proclamation chooses information from one table and embeds it into a new table.

SQL SELECT INTO Syntax

We can duplicate all segments into the new table:

SELECT *
INTO newtable [IN externaldb]
FROM demo1;

Or we can duplicate just the segments we need into the new table:

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

The new table will be made with the segment names and types as characterized in the SELECT proclamation. You can apply new names utilizing the AS clause.


SQL SELECT INTO Examples

Create a reinforcement duplicate of Customers:

SELECT *
INTO CustomersBackup2018
FROM Customers;

Use the IN statement to duplicate the table into another database:

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

Copy just a couple of sections into the new table:

SELECT CustomerName, ContactName
INTO CustomersBackup2018
FROM Customers;

Copy just the usa clients into the new table:

SELECT *
INTO CustomersBackup2018
FROM Customers
WHERE Country='USA';

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

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

Tip: The SELECT INTO explanation can likewise be utilized to make a new, void table utilizing the outline of another. Simply include a WHERE statement that makes the inquiry return no data:

SELECT *
INTO newtable
FROM demo1
WHERE 1=0;