This is the 11th day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021

Have you ever encountered such a mistake in detail?

The devil is in the details!

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:

Problematic SQL statement

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

In an UPDATE statement, if you want to UPDATE multiple fields, do not use “AND” between the fields. Instead, separate them 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!