The SQL SELECT into statement can be used to create a backup copy of the table.
SELECT into statement
The SELECT INTO statement selects data from one table and then inserts the data into another table.
The SELECT into statement is commonly used to create a backup copy of a table or to archive records.
SQL SELECT into syntax
You can insert all the columns into the new table:
SELECT *into new_table_name [in Externaldatabase] from Old_tablename
Or just insert the desired column into the new table:
SELECT column_name (s) to new_table_name [in Externaldatabase] from Old_tablename
SQL SELECT into instance-make backup copy
The following example makes a backup copy of the "Persons" table:
SELECT* INTO Persons_backupfrom Persons
The IN clause can be used to copy a table to another database:
SELECT* INTO IN ' Backup.mdb ' from Persons
If we want to copy some of the fields, we can list them after the SELECT statement:
SELECTLastname,firstname INTO Persons_backupfrom Persons
SQL SELECT into instance-with a WHERE clause
We can also add a WHERE clause. The following example creates a table named "Persons_backup" with two columns by extracting information from the "Persons" table of people residing in "Beijing":
SELECTLastname,firstname INTO persons_backupfrom Persons WHERE city= ' Beijing '
SQL SELECT into instance-connected table
It is also possible to select data from more than one table. The following example creates a new table named "Persons_order_backup" that contains the information obtained from the Persons and Orders two tables:
SELECTPersons.lastname,orders.orderno INTO persons_order_backup FROM Persons INNER JOIN Orders ON persons.id_p=orders.id_ P
SQL SELECT into uses