update set a=2 and b=3 有and 可以执行
2024-07-10 本文已影响0人
低级开发111
数据库:MySQL 5.7

create table tmp_test as
select 1 as id ,1 as a ,2 as b ;
select * from tmp_test
-- 写错了 却可以执行 且a的值变为0 (正确是用逗号)
update tmp_test
set a = 2 and b= 3
where id = 1

SQL 解释器会尝试评估 a = 2 and b = 3 这个表达式
使用了 AND 实际上会将其视为一个条件表达式 ,并尝试将其转换为布尔值
在 SQL 中,布尔值 TRUE 常常会被隐式转换为数值 1,而 FALSE 转换为 0
