Select INTO and insert into Select two table copy statement differences

Source: Internet
Author: User
SELECT * Into Desttbl from SRCTBL
Insert into Desttbl (fld1, fld2) Select Fld1, 5 from Srctbl

The above two sentences are to insert the SRCTBL data into the DESTTBL, but the two sentences are different: the first sentence (select into from) requires that the target table (DESTTBL) does not exist because it is created automatically when inserting. The second sentence (insert into Select from) requires the target table (DESTTBL) to exist , and because the target table already exists, we can insert a constant in addition to the fields in the source table (SRCTBL), as in the example: 5.

1.INSERT into SELECT statement

Statement form: Insert into Table2 (field1,field2,...) Select Value1,value2,... from Table1

The target table Table2 must exist, and because the target table Table2 already exists, we can insert a constant in addition to the fields Table1 the source table.

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.

Reference: http://jingyan.baidu.com/article/d5c4b52b29c326da570dc548.html

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.