A concise tutorial of SQL statements for Linux---INSERT into

Source: Internet
Author: User

So far, we have learned how to get the data out of the table. But what if this information is entered into these forms? This is what this page (INSERTinto) and the next page (UPDATE) will discuss.

Basically, there are two ways in which we can enter data into a table. One is to enter one stroke at a time, and the other is to enter several strokes at a time. Let's take a look at the way to enter a pen first.

In accordance with the usual practice, we introduce grammar first. The syntax for entering a piece of data at a time is as follows:

INSERT into "table name" ("Field 1", "Field 2", ...)
VALUES ("Value 1", "Value 2", ...);

Suppose we have a table with the following schema:

store_information Form

Field name Type of information
Store_name CHAR (50)
Sales Float
Txn_date Datetime

And we're going to put this information into this form: In January, 1999,los Angeles store has $900 turnover. We'll break into the following SQL statement:

INSERT into Store_information (Store_name, Sales, Txn_date)
VALUES (' Los Angeles ', ' jan-10-1999 ');

The second INSERT into allows us to enter more than one pen at a time. Unlike the example above, we are now going to use the SELECT command to specify the data to be entered into the table. If you want to say that this is not to say that the information is from another form, then you want to be right. The syntax for entering more than one pen at a time is:

INSERT into "Table 1" ("Field 1", "Field 2", ...)
Select "Field 3", "Field 4", ...
From "Form 2";

The above syntax is the most basic. This whole sentence of SQL can also contain WHERE, GROUPby, and have clauses, table joins and aliases, and so on.

For example, if we want to put 1998 turnover information into the store_information form and we know that the source of the information can be obtained from the sales_information form, Then we can enter the following SQL:

INSERT into Store_information (Store_name, Sales, Txn_date)
SELECT store_name, Sales, txn_date
From Sales_information
WHERE year (txn_date) = 1998;

Here, I used the function in SQL Server to find the year in the date. Different databases will have different syntax. For example, on Oracle, you will use the where To_char (txn_date, ' yyyy ') = 1998.


Linux is measured as follows:



Reprint please specify: Xiao Liu

A concise tutorial of SQL statements for Linux---INSERT into

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.