首页 > 数据库技术 > 详细

MySQL、You are using safe update mode

时间:2015-04-30 13:58:32      阅读:237      评论:0      收藏:0      [点我收藏+]

MySQL默认模式是sql_safe_updates=1的。在这个模式下不管你是update还是delete一行where 条件都要指定主键。如果where条件只出现的不是主键就会出错。

例子:

  set sql_safe_updates =1;--开始安全更新、这个是我这个例子的前提。

  --第一步:建立两个表

  create table t(x int,y int);

  create table t2(x int primary key,y int);

  --第二步:向表中插入数据

  insert into t(x,y) values(1,1),(2,2),(3,3);

  insert into t2(x,y) values(1,1),(2,2),(3,3);

  --第三步:测试安全更新模式对update delete 的影响。

  update t set y =100 where x=1;--这个会出报错、You are using safe update mode......

  update t2 set y=100 where x=1;--这个就没有事。因为x这表t2中是主键、而在表t中不是。

  --解决方案:

  为了对t表的更新也可以完成、我们就要在update 语句前加上一句。

  set sql_safe_updates =0;--禁用这个模式就可以了

MySQL、You are using safe update mode

原文:http://www.cnblogs.com/JiangLe/p/4468604.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!