SQL Data Add statement

Source: Internet
Author: User

SQL provides two methods for adding new rows to a database relational table, which are single-line INSERT statements and multiple-line INSERT statements. The following is a brief introduction to the functionality and usage of both of these statements.

(1) Single-line INSERT statement

A single-line INSERT statement is used to add a row of new data to a relational table. The use format is as follows:

INSERT into < table name > (List of column names)

Valus (List of column values)

Where the numeric order in the list of column values corresponds to each column name in the table of column names.

(2) Multi-line INSERT statement

Multiple-line INSERT statements are used to add several rows of new data to a relational table, using the following format:

INSERT into < table name > (List of column names)

(SELECT statement)

Example 9: Save the order number, date, and order quantity in the Order table before January 1, 1999 in another relationship table Oldorders.

INSERT into Oldorders

(order_num,order_date,amout)

SELECT Order_num,order_date,amount

From ORDERS

WHERE order_date< "01-jan-99"

The point to note here is that in a multiline INSERT statement, the data source is the result of a SELECT query statement. That is, a multiline insert statement is similar to the copy function of the database content. The order of the columns in the result of the SELECT query statement corresponds to each column name in the list of column names.

References: SQL language tutorials SQL language basics

Back to the database basics ABC Directory

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.