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