Skip to main content

Posts

Showing posts from January, 2010

SQL SELECT INTO Statement

The SQL SELECT INTO statement can be used to create backup copies of tables. The SQL SELECT INTO Statement The SELECT INTO statement selects data from one table, creates a new table with the exact structure and size and inserts automatically the selected data into the new table. SQL SELECT INTO Syntax We can select all columns into the new table: SELECT * INTO new_table_name [IN externaldatabase] FROM old_tablename Or we can select only the columns we want into the new table: SELECT column_name(s) INTO new_table_name [IN externaldatabase] FROM old_tablename SQL SELECT INTO Example Make a Backup Copy - Now we want to make an exact copy of the data in our "Persons" table. We use the following SQL statement: SELECT * INTO Persons_Backup FROM Persons We can also use the IN clause to copy the table into another database: SELECT * INTO Persons_Backup IN 'Backup.mdb' FROM Persons We can also copy only a few fields into the new table: