The MySQL update statement is the update statement in MySQL. When we need to update or modify the data in the table, we will use this update statement. Let's take a look at the specific writing method of the mysql update statement.
#The update statement in MySQL is used to update existing data in the table. You can also use the UPDATE statement to change the column values of a single row, a group of rows, or all rows in a table.
The syntax of the UPDATE statement in MySQL:
Single table
UPDATE [LOW_PRIORITY] [IGNORE] table_reference SET assignment_list [WHERE where_condition] [ORDER BY ...] [LIMIT row_count] value: {expr | DEFAULT}assignment:col_name = value assignment_list:assignment [, assignment] ...
Multiple tables
UPDATE [LOW_PRIORITY] [IGNORE] table_references SET assignment_list [WHERE where_condition]
UPDATE statement updates the table What you need to pay attention to is:
After the UPDATE keyword, specify the name of the table to update the data.
The SET clause specifies the column to be modified and the new value. To update multiple columns, use a comma-separated list.
Use the conditions in the WHERE statement to specify the rows to be updated. The WHERE clause is optional. If the WHERE clause is omitted, the UPDATE statement updates all rows in the table.
If the ORDER BY clause is specified, the rows will be updated in the specified order.
The LIMIT clause is used to give a limit to limit the number of rows that can be updated.
ORDER BY and LIMIT cannot be used when updating multiple tables.
When using the update statement to modify a table:
Single table modification refers to modifying the values of one or more columns of existing data in a specified single table; set phrase Followed by the columns and values to be modified;
where clause indicates which data in the table needs to be modified. If there is no where clause, it means that all rows must be modified;
order by sub The clause indicates that the update data is carried out in the specified order; the
limit clause indicates that the number of rows to be modified is limited;
Multiple table modification refers to modifying the rows that meet the conditions in multiple tables specified by table_references Data and multi-table modifications do not allow the use of order by and limit clauses.
This article has ended here. For more other exciting content, you can pay attention to the MySQL Video Tutorial column on the PHP Chinese website!
The above is the detailed content of How to write mysql update statement?. For more information, please follow other related articles on the PHP Chinese website!