The SQL SELECT INTO Statement in Easy Way

The SQL SELECT INTO Statement

The SELECT INTO account selects abstracts from one table and inserts it into a altered table.

The SELECT INTO account is a lot of generally acclimated to actualize advancement copies of tables.

SQL SELECT INTO Syntax

We can baddest all columns into the new table:

SELECT *

INTO new_table_name [IN externaldatabase]

FROM old_tablename

Or we can baddest alone the columns we wish into the new table:

SELECT column_name(s)

INTO new_table_name [IN externaldatabase]

FROM old_tablename

SQL SELECT INTO Example

Make a Advancement Archetype - Now we wish to accomplish an exact archetype of the abstracts in our "Persons" table.

We use the afterward SQL statement:

SELECT *

INTO Persons_Backup

FROM Persons

We can aswell use the IN article to archetype the table into addition database:

SELECT *

INTO Persons_Backup IN 'Backup.mdb'

FROM Persons

We can aswell archetype alone a few fields into the new table:

SELECT LastName,FirstName

INTO Persons_Backup

FROM Persons

SQL SELECT INTO - With a WHERE Clause

We can aswell add a WHERE clause.

The afterward SQL account creates a "Persons_Backup" table with alone the bodies who lives in the city-limits "Sandnes":

SELECT LastName,Firstname

INTO Persons_Backup

FROM Persons

WHERE City='Sandnes'

SQL SELECT INTO - Joined Tables

Selecting abstracts from added than one table is aswell possible.

The afterward archetype creates a "Persons_Order_Backup" table contains abstracts from the two tables "Persons" and "Orders":

SELECT Persons.LastName,Orders.OrderNo

INTO Persons_Order_Backup

FROM Persons

INNER JOIN Orders

ON Persons.P_Id=Orders.P_Id

Comments