使用AND而不是COMMA时,UPDATE语句未生成语法错误 [英] UPDATE Statement not generating syntax error when using AND instead of COMMA
问题描述
我正在浏览有关更新的MySQL文档. 请参见UPDATE语法 .我发现语法是
I was browsing on MySQL Documentation about the update. See UPDATE Syntax. I found out that the syntax is
UPDATE [LOW_PRIORITY] [IGNORE] table_reference
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
我执行此语句时
UPDATE SampleTB
SET NAME = '123' AND Address = '456'
WHERE ID = 1;
See Here for SQL Fiddle Demonstration Link
查询成功执行,Name
的值为0
.我期待查询出现语法错误.
The query executed successfully and the value of Name
was 0
. I was expecting a syntax error on the query.
有人可以向我解释为什么它没有产生错误吗?为什么该列的新值是zero
而不是123
?
Can somebody explain to me why it didn't generate an error? And why was the new value of the column is zero
and not 123
?
推荐答案
SET NAME = '123' AND Address = '456'
解析为以下内容:
SET NAME = ('123' AND (Address = '456'))
是一个字符串和布尔操作数的比较和布尔AND
.
which is one comparison and boolean AND
of a string and boolean operands.
因此它获取当前行的Address
列值,将其与'456'
字符串进行比较,并且比较结果用作AND
的第二个操作数,如'123' AND false
So it takes the current row's Address
column value, compares it to a '456'
string and result of the comparison is used as a second operand for AND
like '123' AND false
这篇关于使用AND而不是COMMA时,UPDATE语句未生成语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!