Update 變更紀錄

  1. 先列出資料表中的紀錄。
    MariaDB root@(none):dyw> select * from tbl;
    +----+---------+--------+-----------------+
    | id | title   | author | submission_date |
    +----+---------+--------+-----------------+
    | 1  | PHP     | david  | 2025-11-10      |
    | 2  | Linux   | linux  | 2025-11-10      |
    | 3  | Mariadb | dywang | 2025-11-11      |
    +----+---------+--------+-----------------+
    
    3 rows in set
    Time: 0.037s
    
  2. 變更紀錄 id=1 的 title 為 Python。
    MariaDB root@(none):dyw> update tbl set title='Python' where id=1;
    Query OK, 1 row affected
    Time: 0.028s
    
  3. 再列出資料表中的紀錄,紀錄 id=1 的 title 已更新為 Python。
    MariaDB root@(none):dyw> select * from tbl;
    +----+---------+--------+-----------------+
    | id | title   | author | submission_date |
    +----+---------+--------+-----------------+
    | 1  | Python  | david  | 2025-11-10      |
    | 2  | Linux   | linux  | 2025-11-10      |
    | 3  | Mariadb | dywang | 2025-11-11      |
    +----+---------+--------+-----------------+
    
    3 rows in set
    Time: 0.017s
    
  4. 一次更新一筆紀錄的 2 個欄位。
    MariaDB root@(none):dyw> update tbl set title='C++',author='peter' where id=1;
    Query OK, 1 row affected
    Time: 0.013s
    
  5. 再列出資料表中的紀錄,紀錄 id=1 的 title 及 author 2 個欄位都已更新。
    MariaDB root@(none):dyw> select * from tbl;
    +----+---------+--------+-----------------+
    | id | title   | author | submission_date |
    +----+---------+--------+-----------------+
    | 1  | C++     | peter  | 2025-11-10      |
    | 2  | Linux   | linux  | 2025-11-10      |
    | 3  | Mariadb | dywang | 2025-11-11      |
    +----+---------+--------+-----------------+
    
    3 rows in set
    Time: 0.012s