Linux SQL statement Concise tutorial---UPDATE DELETE from

Source: Internet
Author: User

We may sometimes need to modify the information in the form. At this point, we need to use the UPDATE command. The syntax for this instruction is:

UPDATE "Table name"
SET "Field 1" = [New value]
WHERE "condition";

The easiest way to understand this syntax is through an example. Suppose we have the following table:

store_information Form

Store_name Sales Txn_date
Los Angeles 1500 05-jan-1999
San Diego 250 07-jan-1999
Los Angeles 300 08-jan-1999
Boston 700 08-jan-1999

We found that the turnover of Los Angeles in 08-jan-1999 was actually $, not the one stored in the table, so we used the following SQL to modify that information:

UPDATE store_information
SET Sales = 500
WHERE store_name = ' Los Angeles '
and txn_date = ' jan-08-1999 ';

Now the contents of the table become:

store_information Form

Store_name Sales Txn_date
Los Angeles 1500 05-jan-1999
San Diego 250 07-jan-1999
Los Angeles 500 08-jan-1999
Boston 700 08-jan-1999

In this example, only one of the data conforms to the conditions in the WHERE clause. If more than one information is eligible, each qualifying document will be modified.

We can also modify several fields at the same time. This syntax is as follows:

UPDATE "Table"
SET "Field 1" = [value 1], "field 2" = [value 2]
WHERE "condition";





In some cases, we will need to remove some data directly from the database. This can be achieved by the DELETE from command. Its syntax is:

DELETE from "table name"
WHERE "condition";

Let's use an example to illustrate this. Suppose we have the following table:

store_information Form

Store_name Sales Txn_date
Los Angeles 1500 05-jan-1999
San Diego 250 07-jan-1999
Los Angeles 300 08-jan-1999
Boston 700 08-jan-1999

And we need to get rid of all the data about Los Angeles. Here we can use the following SQL to achieve this purpose:

DELETE from Store_information
WHERE store_name = ' Los Angeles ';

Now the contents of the table become:

store_information Form

Store_name Sales Txn_date
San Diego 250 07-jan-1999
Boston 700 08-jan-1999





Finally, attach a gadget for everyone to practice the SQL statement: http://www.uzzf.com/soft/28655.html


Reprint please specify: Xiao Liu

Linux SQL statement Concise tutorial---UPDATE DELETE from

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.