在一条update语句中,如果要更新多个字段,字段间不能使用 and 而应该用逗号。
update student set age = 10 and name = '张三' where id = '1' ×
update student set age = 10,name = '张三' where id = '1' √
有个问题运行sql1后发现名字没有改变但是age变成了0
update student set age = 10 and name = '张三' where id = '1' 等价于
update student set age = (10 and name = '张三' ) where id = '1' 而 (10 and name = '张三' ) 是一个逻辑表达式。因此,这个逻辑表达式的结果为 false , false在MySQL中等价于0!所以会出现age=0 但是name没有改变