The database inserts the data the select to from and inserts into select distinguishes the detailed explanation _ the database other

Source: Internet
Author: User

May First Contact Select...into...from ... and insert Into...select ... There are many people will misunderstand, from the surface are all the relevant information query out, and then add to a table, in fact, is far from so simple, next, the pig with the most common expression for you to introduce the difference between the two.

Steps/Methods

1. First, let's take a look at the INSERT INTO SELECT statement, whose syntax is: INSERT INTO Table2 (field1,field2,...) Select Value1,value2,... from Table1.

2, the requirement here is that Table2 must already exist, if it does not exist, the system will prompt the object is invalid.

3, at the same time because Table2 already exist, so we can arbitrarily to add to the Table2 content of the column type, of course, including constants, perhaps through the following diagram, you will find the introduction of constants when the unusual phenomenon.

4. Next, select into the From statement, which is the form: select Vale1, value2 into Table2 from Table1.

5, here is required MyTable1 does not exist, because in the insertion time, the system will automatically create MYTABLE1, if the previous MyTable1 has been created, the system will be prompted to already have the table.

6, it is because of this feature, will bring us a lot of convenience, first of all, if I just want to MyTable2 the ID column in the table, then I just need to select the ID column, and then add to the new table can be.

7, if I want the Name column in MyTable2, then I just need to select the Name column and add it to the new table.

End

Attention matters

Application scope by the practitioner to find the answer themselves ~

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.