Home > Database > Mysql Tutorial > body text

MySQL的Update语句Set顺序问题

WBOY
Release: 2016-06-07 15:01:23
Original
1591 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 1. 测试一 create table test(id int, tag int, num int); insert into test (id, tag, num) values(1, 1, 1), (2,2, 2), (3,3,3); update test set tag = 4, num=case when tag=4 then 4 else 3 end

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  1. 测试一 create table test(id int, tag int, num int);

  insert into test (id, tag, num) values(1, 1, 1), (2,2, 2), (3,3,3);

  update test set tag = 4, num=case when tag=4 then 4 else 3 end where tag=3;

  select * from test;

  (1)sqlserver2014的结果:

MySQL的Update语句Set顺序问题

  (2)MySQL的结果:

MySQL的Update语句Set顺序问题

  2. 测试二:更换set语句的顺序 create table test(id int, tag int, num int);

  insert into test (id, tag, num) values(1, 1, 1), (2,2, 2), (3,3,3);

  update test set num=case when tag=4 then 4 else 3 end, tag = 4 where tag=3;

  select * from test;

  (1)sqlserver2014的结果:

MySQL的Update语句Set顺序问题

  (2)MySQL的结果

MySQL的Update语句Set顺序问题

  MySQL的update语句,set列的顺序是有关系的,后面列的计算是以前面列的结果为基础的,即从左向右评估;

  (2)SQLServer的update语句,set的顺序无关,所有的更改都是基于之前取出的快照;

MySQL的Update语句Set顺序问题

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!