SQL Tutorial: SQL SELECT INTO tutorial

Source: Internet
Author: User
Tags sql tutorial

SQL SELECT INTO tutorial

The SQL SELECT INTO statement can be used to create a backup copy table.

In the SQL SELECT INTO statement
In the select into statement, SELECT data from a table and insert it to a different table.

The select into statement is the table most frequently used to create backup copies.

Selected SQL syntax
We can select all columns to the new table:

SELECT *INTO new_table_name [IN externaldatabase] FROM old_tablename

Or we can select only the columns for the new table:

SELECT column_name(s)INTO new_table_name [IN externaldatabase] FROM old_tablename
 

Select database to Example
Make backup copies-now we want to accurately copy the data at our "people" seat.

We use the following SQL statement

SELECT *INTO Persons_BackupFROM Persons
 

We can also use the clause to copy the table to another database:

 

SELECT *INTO Persons_Backup IN 'Backup.mdb'FROM Persons
 
Or we can do the same.
 
SELECT LastName,FirstNameINTO Persons_BackupFROM Persons
 
 

Go to database selection-with a w here clause
We can also add a WHERE clause.

The following statement creates a "Persons_Backup" table. Only the persons who live in the city "Sanes ":

SELECT LastName,FirstnameINTO Persons_BackupFROM PersonsWHERE City='Sandnes'

Choose database> Add Table
It is also possible to select data from more than one table.

The following example creates a "Persons_Order_Backup" table that contains data from two tables: "person" and "order ":

 

SELECT Persons.LastName,Orders.OrderNoINTO Persons_Order_BackupFROM PersonsINNER JOIN OrdersON Persons.P_Id=Orders.P_Id
 

Related Article

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.