更新数据——update
# 更新数据
# 方式一
update <TableName> set <Value1>, <Value2> ... where <Condition>;
1
Value1
、Value2
...就是要被更新的值,根据 Condition
来更新。
# 方式二
update <TableName> set <Vaue1>, <Value2> ... where <Condition1> and <Condition2>;
1
update <TableName> set <Vaue1>, <Value2> ... where <Condition1> or <Condition2>;
1
使用 and
和 or
关键字。
# Example
有如下一张 student
表:
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | tom | 18 |
| 2 | jim | 18 |
+----+------+------+
1
2
3
4
5
6
2
3
4
5
6
更新表:
update student set name='Tom' where id=1;
1
update student set name='Jim', age=20 where id=2;
1
查看表:
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | Tom | 18 |
| 2 | Jim | 20 |
+----+------+------+
1
2
3
4
5
6
2
3
4
5
6
编辑 (opens new window)
上次更新: 2022/09/26, 16:55:15