【容易犯错的update操作】UPDATE 的 ,与 and
2011-08-05 15:29
183 查看
我们在1条SQL中对多值update 时,有木有被'and'迷惑,误将 ',' 写成了'and'。
下面看看两个语句的区别,我们目的要将beijing 表 id<=2 的 uid gid 的值各 +1000 :
#1 update beijing set uid=uid+1000 and gid=gid+1000 where id <=2 ;
#2 update beijing set uid=uid+1000 , gid=gid+1000 where id <=2 ;
1、首先看数据:
2、#1的update操作,Query OK,匹配了2条并变更了2条。并且NO warnings; 这时候我们可能认为SQL执行正确。
再select beijing表,id<=2 的uid=0 , 而gid 没有变化,显然不是我们想要的结果。
3、为什么会产生错误的结果呢? 我们看下面SQL,MySQL将“uid+1000 and gid=gid+1000”的值赋给了 uid ,
“uid+1000 and gid=gid+1000”这个条件为假,MySQL中假即 = 0 ,从而导致了 uid 赋值为0 而 gid 并未更新。
4、正确的写法如 #2 update beijing set uid=uid+1000 , gid=gid+1000 where id <=2 ;
下面看看两个语句的区别,我们目的要将beijing 表 id<=2 的 uid gid 的值各 +1000 :
#1 update beijing set uid=uid+1000 and gid=gid+1000 where id <=2 ;
#2 update beijing set uid=uid+1000 , gid=gid+1000 where id <=2 ;
1、首先看数据:
2、#1的update操作,Query OK,匹配了2条并变更了2条。并且NO warnings; 这时候我们可能认为SQL执行正确。
再select beijing表,id<=2 的uid=0 , 而gid 没有变化,显然不是我们想要的结果。
3、为什么会产生错误的结果呢? 我们看下面SQL,MySQL将“uid+1000 and gid=gid+1000”的值赋给了 uid ,
“uid+1000 and gid=gid+1000”这个条件为假,MySQL中假即 = 0 ,从而导致了 uid 赋值为0 而 gid 并未更新。
4、正确的写法如 #2 update beijing set uid=uid+1000 , gid=gid+1000 where id <=2 ;
相关文章推荐
- SVN学习笔记11 -- Eclipse 中 SVN的相关操作 -- checkout and update
- MySQL语法(二 )--update--and 和 or--order by--delect(数据的操作)----drop(库的操作)
- Java操作ElasticSearch之Update数据 and Java操作ElasticSearch之Delete数据
- 网站后台登录aspcms 提示错误号:-2147467259,错误描述:操作必须使用一个可更新的查询。sql=update AspCms_Content set TimeStatus=0 where TimeStatus=1 and Timeing <= 解决方法。
- 关于职称计算机考试升级操作容易犯错而丢分的地方分析
- mongodb,update和 findAndModify操作。
- 用户容易忽视的网络安全错误操作盘点
- JS容易犯错的this和作用域
- Mongodb的update操作
- WPF and Silverlight 学习笔记(二十八):基本图形的使用(3)图形的操作
- Codeforces Round #261 (Div. 2)-A. Pashmak and Garden(容易)
- Linux设备驱动程序学习(6)-高级字符驱动程序操作-ioctl and llseek
- insert/update操作失败原因及解决方法
- HDU 3911 Black And White(线段树区间合并+lazy操作)
- rosdep init and update Error
- MySQL与SqlServer中update操作同一个表问题
- 在Sql Server触发器中判断操作是Insert还是Update还是Delete
- C++ - 类的赋值操作 使用 "复制-交换(copy and swap) 技术" 详解
- 数据库--MyBatis的(insert,update,delete)三种批量操作
- 在Sql Server触发器中判断操作是Insert还是Update还是Delete