SQL Tutorial: SQL SELECT into instance tutorial

Source: Internet
Author: User
Tags sql tutorial one table

SQL Tutorial: SQL SELECT into instance tutorial

A table in which the SQL SELECT into statement can be used to make a backup copy.

In SQL SELECT into statement
Select the data from a table in the SELECT INTO statement and insert it into a different table.

The SELECT INTO statement is the most frequently used to create a backup copy of the table.

The SQL syntax that you selected
We can select all columns to the new table:

Select *
into New_table_name [in Externaldatabase]
from Old_tablename
or we can select only columns we're going to the new table: Select Column_ Name (s)
into new_table_name [in Externaldatabase]
the From old_tablename database is selected for example to make a backup copy-now we want to accurately replicate the data in our "people" seating. We use the following SQL statement: SELECT *
into Persons_backup
The from Persons can do the same. SELECT *
into persons_backup in ' Backup.mdb '
From Persons we can also replicate only a few areas into the new table: Select Lastname,firstname
into Persons_backup
from Persons to the database selection-with a W Here clause we can also add a WHERE clause. The following statement creates a "persons_backup" table, and only the people who live in the city "Sandnes": Select Lastname,firstname
into Persons_backup
from Persons
where city= ' Sandnes ' into the database selection-join table selection data from more than one table is also possible. The following example creates a "persons_order_backup" table that contains data from two tables "people" and "orders": SELECT Persons.lastname,orders.orderno
into Persons_order_ Backup
from Persons
INNER JOIN Orders
on persons.p_id=orders.p_id

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.