Detailed description of the differences between select into from and insert into select for database data insertion

Source: Internet
Author: User

Maybe the first time I came into contact with select... into... from... and insert... select... many people may misunderstand that, on the surface, it is not that simple to query relevant information and add it to a table. Next, pig will introduce the differences between the two in the most common expression.

STEP/Method

1. First, let's take a look at the insert into select statement. Its Syntax format is: Insert into Table2 (field1, field2,...) select value1, value2,... from Table1.

2. The requirement here is that table 2 must already exist. If it does not exist, the system will prompt that the object is invalid.

3. Because Table2 already exists, we can add content that conforms to the column type to Table2 at will. Of course, it also includes constants. You may find that through the following figure, it is unusual to import constants.

4. Next, let's talk about the select into from statement. The syntax format is SELECT vale1, value2 into Table2 from Table1.

5. MyTable1 does not exist, because MyTable1 is automatically created during insertion. If MyTable1 has been created before, the system will prompt that the table already exists.

6. This feature will bring us a lot of convenience. First, if I only want to select the ID column in MyTable2, then add it to the new table.

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

END

Notes

The application scope is determined by the practitioners 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.