Copying from One Table to Another in SQL

Leave a Comment

To copy the contents of a table into a brand new table (one that is created on-the-fly) you can use the SELECT INTO statement.

The following example demonstrates the use of SELECT INTO :
SELECT *
INTO CustumerCopy
FROM Customers;

This SELECT statement creates a new table named CustumerCopy and copies the entire contents of the Customers table into it. Because SELECT * was used, every column in the Customers table will be created (and populated) in the CustumerCopy table.

To copy only a subset of the available columns, explicit column names can be specified instead of the * wildcard character.

CREATE TABLE CustumerCopy AS
SELECT * FROM Customers;

0 comments:

Post a Comment