关于mysql:MySql-update-逗号-and的区别

7次阅读

共计 365 个字符,预计需要花费 1 分钟才能阅读完成。

更新语句正确的写法
update table_name set column1 = 'value1', column2 = 'value2' where id = 1
更新语句谬误的写法
update table_name set column1 = 'value1' and column2 = 'value2' where id = 1
运行谬误写法的后果
column1 会被更新为 0
起因剖析

应用 and 连接符时,该语句会被解析为

update table_name set column1 = ('value1' and column2 = 'value2') where id = 1

而 (‘value1’ and column2 = ‘value2’) 是一个逻辑表达式,因为 column2 = ‘value2’ 并不成立,故 (column2 = ‘value2’) 的后果为 0,此时表达式等效为 (1 and 0),故理论的后果被更新为 0

正文完
 0