This article mainly takes you to understand and use the MySQL Update statement to update existing records in the database table.
Basic syntax of the Update statement:
UPDATE <表名> SET 字段 1=值 1 [,字段 2=值 2… ] [WHERE 子句 ]
[ORDER BY 子句] [LIMIT 子句]
Copy after login
: used to specify the name of the table to be updated.
SET clause: used to specify the column name and column value to be modified in the table. Among them, each specified column value can be an expression or the default value corresponding to the column. If a default value is specified, the column value can be represented by the keyword DEFAULT.
WHERE Clause: Optional. Used to limit the rows in the table to be modified. If not specified, all rows in the table will be modified.
ORDER BY clause: optional. Used to limit the order in which rows in a table are modified.
LIMIT clause: optional. Used to limit the number of rows that are modified.
First, create a new database:
CREATE TABLE tasks (
id INT NOT NULL,
subject VARCHAR(45) NULL,
start_date DATE NULL,
end_date DATE NULL
)charset utf8;
Copy after login
Secondly, insert data:
insert into tasks values(1,'math',2029-6-1,2060-6-1)
Copy after login
Finally, update the data:
UPDATE `tasks` SET `start_date`='2029-6-1', `end_date`='2060-6-1' WHERE (`id`='1') AND (`subject`='math') AND (`start_date`='0000-00-00') AND (`end_date`='0000-00-00') LIMIT 1
Copy after login
Note: Ensure that Update ends with a WHERE clause, passed # The ##WHERE clause specifies the conditions that the updated records need to meet. If the WHERE clause is ignored, MySQL will update all rows in the table.
Recommended:
mysql tutorial
The above is the detailed content of How to update table data in MySQL database. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn