SQL Tutorial: SQL SELECT into tutorial

Source: Internet
Author: User
Tags sql tutorial one table

SQL SELECT into 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 just select the column we want to go to the new table:

 Select column_name (s) into new_table_name [in ex Ternaldatabase] from Old_tablename 
   
 
     
     

Database selected to For example
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 from Persons 
   
 Div id= "Result_box" dir= "ltr" > 

We can also use the terms in this table to replicate to another database:

 

 SELECT * into Persons_

      Backup in ' Backup.mdb ' from Persons 
   
 or we can do so. 
   
 
 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, and only the people who live in the city "Sandnes":

 SELECT lastname,firstname into Persons_backup from sons where city= ' Sandnes ' 
 
   
   

Go to database selection-Join table
Select data from more than one table is also possible. The following example of

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 
&NBSP 

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.