Insert Select Strip Select Copy one table to another table

Source: Internet
Author: User
Tags one table
Insert Select Strip Select to copy a table to another

Copy the statement using the SELECT INTO and INSERT into the Select table.

1.INSERT into SELECT statement

Statement form: Insert into Table2 (field1,field2,...) Select Value1,value2,... from Table1 [where column =value][] For optional content The target table Table2 must be present because the target table Table2 already exists, so we can insert constants in addition to the fields Table1 the source table. Examples are as follows:

Insert into TJJRMX (Yybh,xh,tjxmbh,jg,sfyx,zhxmbh,tjksbh,jcrq,jcys,ts,ckfw,disporder)
Select ', Xh,tjxmbh,jg,sfyx,zhxmbh,tjksbh,jcrq,jcys,ts,ckfw,disporder from tjjrmx where yybh = 5

2.SELECT into from statement

Statement form: SELECT vale1, value2 into Table2 from Table1

The target table Table2 does not exist because the table Table2 is created automatically at insert time and the specified field data in Table1 is copied to Table2. Examples are as follows:

3. from one database to another

The statement is: INSERT into the database name. Frame name-table name (column name) select (column name) from database name. frame name. Table name WHERE condition

For example: INSERT INTO MYEMP.DBO.TJDJB (YYBH)
Select Yybh from MYCMD.DBO.TJDJB where djrq= ' 2009-10-15 ' and yybh = ' 11 ' table

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.