SQL Insert data Three common methods and tips _ database other

Source: Internet
Author: User
Copy Code code as follows:

INSERT into table1 (ID, name, address) VALUES (1, YGL, ' Beijing ') apply to T-SQL and Pl/sql
SELECT ID, name, address to table2 from table1 automatically create Table2,t-sql usage
INSERT into table2 (ID, name, address) SELECT ID, name, address from table1

Here is a simple third sentence, because you can specify the columns to be inserted into the talbe2, and the data source can be obtained through a relatively complex query statement, it may be more flexible to use, but we must also note that when we specify the columns of the target table, we must fill in all the Non-empty columns. Otherwise, you won't be able to insert data, and one of the more error-prone areas is when we write the following shorthand format:
Copy Code code as follows:

INSERT into table2 SELECT ID, name, address from table1

At this point, if we skip the column in the target table, the default is to insert data into all the columns of the target table, and the column after the select must be in exactly the same order as the column in the destination table to complete the correct data insertion, which is an easy place to overlook.

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.