更新数据
在MySQL中,可以使用update语句来修改、更新表中的数据。
update <表名> set <字段1>=<值1> [,<字段2>=<值2>…<字段n>=<值n>] [where <更新条件>];
- set子句用于指定表中要修改的字段名及其字段值。每个指定的值可以是表达式,也可以是该字段对应的默认值。如果指定的是默认值,可用关键字default。
- where子句用于限定表中要修改的行。若不指定,则修改表中所有的行。
- 修改多个字段值时,set子句的每个值用逗号分开即可。
示例1:将stu表中学生性别为'未知'的修改为'男'
update stu set s_gender='男' where s_gender='未知';