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