SQL SELECT INTO statement can be used to create backup copies of the table.
SELECT INTO statement
SELECT INTO statement to select data from a table, and the data into another table.
SELECT INTO statement is used to create backup copies of tables or for archiving records.
SQL SELECT INTO Syntax
You can put all the columns into the new table:
SELECT * INTO new_table_name [IN externaldatabase] FROM old_tablename
Or only the desired columns into a new table:
SELECT column_name(s) INTO new_table_name [IN externaldatabase] FROM old_tablename
SQL SELECT INTO Example - make a backup copy
The following example will make a backup copy "Persons" table:
SELECT
*INTO
Persons_backup FROM Persons
IN clause can be used to copy another database tables:
SELECT
*INTO
PersonsIN
'Backup.mdb' FROM Persons
If we want to copy certain domains, these domains can be listed after the SELECT statement:
SELECT
LastName,FirstNameINTO
Persons_backup FROM Persons
SQL SELECT INTO instance - with a WHERE clause
We can also add a WHERE clause.
The following example by extraction living in "Beijing" of information from the people "Persons" table, create a table with two columns titled "Persons_backup" of:
SELECT
LastName,FirstnameINTO
Persons_backup FROM PersonsWHERE
City='Beijing'
SQL SELECT INTO Example - tables are linked
Select data from more than one table can be done also.
The following example creates a new table named "Persons_Order_Backup", which contains the information obtained from the two tables Persons and Orders:
SELECT
Persons.LastName,Orders.OrderNoINTO
Persons_Order_BackupFROM
PersonsINNER JOIN
OrdersON
Persons.Id_P=Orders.Id_P