美文网首页
update set a=2 and b=3 有and 可以执行

update set a=2 and b=3 有and 可以执行

作者: 低级开发111 | 来源:发表于2024-07-10 16:51 被阅读0次

数据库:MySQL 5.7


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

相关文章

网友评论

      本文标题:update set a=2 and b=3 有and 可以执行

      本文链接:https://www.haomeiwen.com/subject/ltdthjtx.html