Set sequence of MySQL Update statements

Source: Internet
Author: User
Tags mysql update

1. Test 1Create table test (id int, tag int, num int );
Insert into test (id, tag, num) values (1, 1, 1), (2, 2), (3, 3 );
Update test setTag = 4, num = case when tag = 4 then 4 else 3 endWhere tag = 3;
Select * from test;
(1) sqlserver2014 results:

(2) MySQL results:


2. Test 2: sequence of changing the set statementCreate table test (id int, tag int, num int );

Insert into test (id, tag, num) values (1, 1, 1), (2, 2), (3, 3 );
Update test setNum = case when tag = 4 then 4 else 3 end, tag = 4 <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Upper + lower "http://www.2cto.com/uploadfile/Collfiles/20140327/2014032709015710.jpg" alt = "\">

(2) MySQL results


Conclusion:
(1) In the MySQL update statement, the sequence of the set columns is related. The calculation of the following columns is based on the results of the preceding columns, that is, evaluation from left to right;
(2) in SQL Server's update statement, the set sequence is irrelevant, and all changes are based on the snapshots taken previously;


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.