Several times recently, some developers asked me on Dingding, such as the picture below:
Update a record in MySQL, the syntax is correct, but the record is not updated…
When I first encountered this problem, I took this statement and directly executed it in the test library. I found that there was a problem, but there was still a difference with the development description. Here I use the test data to simulate:
SQL statement with problem:
The record before execution looks like this:
The record after execution looks like this:
As you can see, the result is not “as if it didn’t work”, but actually it does:
why?
MySQL > update MySQL > update MySQL > update MySQL
The format of assignment_list is a comma-separated list of col_name=value.
Go back and try again:
Sure enough, I got the result I wanted!
Summary: If you want to UPDATE multiple fields in an UPDATE statement, do not use “AND” between the fields. Instead, separate the fields with commas.
Owner_code =0; owner_code=0; After many attempts:
Is equivalent to:
(‘43212′ and owner_name=’ li si ‘) is a logical expression, and it is not obvious that owner_name is not ‘Li Si’.
Therefore, the result of this logical expression is false, which in MySQL is equivalent to 0!