SQL Tutorial: SQL SELECT INTO instance tutorial

Source: Internet
Author: User

SQL Tutorial: SQL SELECT INTO instance 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 column to which we want to go to the new table: SELECT column_name (s)
INTO new_table_name [IN externaldatabase]
FROM old_tablename database select to make backup copy for example-now, we want to accurately copy the data at our "people" seat. We use the following SQL statement: SELECT *
INTO Persons_Backup
FROM Persons can also be like this. SELECT *
INTO Persons_Backup IN 'backup. mdb'
FROM Persons, we can also copy tables that only have a few fields to enter the new table: SELECT LastName, FirstName
INTO Persons_Backup
FROM 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 one person lives in the city "Sanes": SELECT LastName, Firstname
INTO Persons_Backup
FROM Persons
WHERE City = 'sandes' it is also possible to enter database selection-Add Table 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. 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.