日期:2014-05-16  浏览次数:20739 次

mysql中这条语句怎么会出错?
SQL code

start transaction;

update participants set cash=cash-12.99 where id=1;
update participants set cash=cash+12.99 where id=2;
update trunks set owner=1 where name='Abacus' and owner=2;

select * from participants;



update trunks set owner=1 where name='Abacus' and owner=2;这条语句出错:
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

为什么会这样??我的记录,字段,类型都没有错的,而且我在my.ini中也#safe-mode了,为什么还是这样子呢?

------解决方案--------------------
SET SQL_SAFE_UPDATES=0;
再试试

使用安全更新模式的时候update语句必须使用一个关键字列属性来限定更新的范围。如果不使用关键字列来限定范围或更新所有记录的时候就不能用安全更新模式。

解决办法是执行以下语句设置为非安全更新模式.

SET SQL_SAFE_UPDATES=0;
------解决方案--------------------
show variables like '%sql_safe_update%';看看sql_safe_update的值是什么

如果是on 就在执行set sql_safe_updates=off