Loading lesson path
statement is used to create a new table and fill it with data from an existing table.
statement is useful for creating backups or for creating a temporary table for analysis.
The new table will be created with the same column names and data types as defined in the source table. However, primary keys, indexes, or NOT NULL constraints are not automatically transferred.
Copy entire table into a new table:
SELECT * INTOnewtable [IN external_db ]
sourcetable
condition
;Copy only some columns into a new table:
column1, column2, column3, ...
newtable [IN external_db ]
sourcetable
condition;The following SQL creates a backup copy of the "Customers" table:
SELECT * INTO CustomersBackup2026
FROM Customers;
The following SQL creates a backup copy of the "Customers" table in another database
('Backup.mdb'):
SELECT *
INTO CustomersBackup2026 IN 'Backup.mdb'
FROM Customers;
The following SQL copies only a few columns from the "Customers" table into a new table:SELECT CustomerName, ContactName INTO Customers2
FROM Customers;
The following SQL copies only the customers from USA in the "Customers"table, into a new table:
SELECT *INTO US_Customers
WHERE Country = 'USA';The following SQL copies data from more than one table into a new table:
SELECT Customers.CustomerName, Orders.OrderID INTO CustomersOrderON Customers.CustomerID = Orders.CustomerID;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 * INTOnewtable
sourcetable
WHERE 1 = 0;