Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand MySQL UPDATE statement

2025-03-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to understand MySQL UPDATE sentences". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Catalogue

1. Problematic SQL statements

Someone asked, for example, the following picture:

The problem can be summed up as follows: update a record in MySQL, the syntax is correct, but the record is not updated.

When I first encountered this problem, I got this statement and executed it directly in the test library. I found that there was a problem, but it was still different from the one described by the developer. Here, I use the test data to simulate:

1. Problematic SQL statements

The record after execution is:

As you can see, the result is not like what the developer said, "it seems to have no effect". In fact, it is effective:

Why?

It seems that there is nothing wrong with the syntax. I have flipped through the update syntax of the official MySQL document:

Seeing that the format of assignment_list is a comma-separated col_name=value list, it suddenly becomes clear that the multi-field update statement that the developer wants should be written as follows:

Go back and try again.

Sure enough, this got the desired result!

Summary: in a UPDATE statement, if you want to update multiple fields, you cannot use "AND" between the fields, but should be separated by commas.

Postscript: later, when I am free, I look back and see why there is a strange result of owner_code=0 when I use "AND" separation. After many attempts, I found that:

Equivalent to:

While ('43212' and owner_name=' Li Si') is a logical expression, it is not difficult to know that owner_name is not'Li Si'. Therefore, the result of this logical expression is false, and false is equivalent to 0! in MySQL.

This is the end of "how to understand MySQL UPDATE sentences". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report