MySQL UPDATE 語句:更新數據
mysql update 語句:更新數據
mysql 數據庫使用 update 語句來修改或者更新已經存在的數據。
我們可以通過 mysql> 命令窗口向表中插入數據,或者通過php腳本來插入數據。
1. mysql update 語句的語法
update table_name set field1=new-value1, field2=new-value2 [where clause]
- update 語句能夠同時更新多個字段。
- update 語句能夠在 where 子句中指定更新條件。
當你需要更新數據表中指定行的數據時 where 子句是非常有用的。
2. 通過命令窗口更新數據
在以下范例中,我們更新數據表中 id 為 3 的 title 字段值:
mysql 范例
mysql> update article set title='學習 c++' where id=3;
query ok, 1 rows affected (0.01 sec)
mysql> select * from article where id=3;
+-----------+--------------+---------------+-----------------+
| id | title | author | submission_date |
+-----------+--------------+---------------+-----------------+
| 3 | 學習 c++ | yapf.com | 2016-05-06 |
+-----------+--------------+---------------+-----------------+
1 rows in set (0.01 sec)