Copy One Table to Another in SQL

Let’s see, How can you copy one Table to another in SQL. In SQL,  INSERT INTO SELECT statement is used to copy the records from one table and insert into another table.

 

The INSERT INTO SELECT statement selects data from one table and inserts it into an existing table. Any existing rows in the target table are unaffected.

SQL Syntax :

SQL> INSERT INTO table2
SELECT * FROM table1;

 

SQL INSERT INTO SELECT Examples

Copy only a few columns from “Suppliers” into “Customers”.

SQL > INSERT INTO Customers (CustomerName, Country)
SELECT SupplierName, Country FROM Suppliers;

 

Copy only the French suppliers into “Customers”

SQL > INSERT INTO Customers (CustomerName, Country)
SELECT SupplierName, Country FROM Suppliers
WHERE Country=’France’;

 

0 Comment

Leave a Reply