我知道我可以在MySQL中关闭安全模式,所以我不想解决这个问题。
我有张简单的桌子:
create table rubbish(
id int auto_increment primary key,
stuff text,
nonsense text
);这里,id是主键。
打开安全模式后,我尝试如下:
update rubbish set nonsense=stuff where id=id; -- fails
update rubbish set nonsense=stuff where id is not null; -- fails
update rubbish set nonsense=stuff where id<>0; -- works与MySQL中的大多数错误消息一样,错误消息也没有帮助:
You are using safe update mode and you tried to update
a table without a WHERE that uses a KEY column在所有情况下,我都使用了键列,所以消息什么也解释不了。MySQL实际上要求我对键列做什么?
发布于 2018-07-21 03:37:35
MySQL SQL_SAFE_UPDATES 防止您在UPDATE和DELETE语句中误用键。为了了解给出的一些条件,对MySQL引擎进行了优化。
... WHERE `id` IS NOT NULL;主键永远不可能为null,因此这始终是true。同样的也适用于
... WHERE `id`=`id`;和
... WHERE TRUE;这些被认为是对钥匙的误用。他们是被禁止的。
https://stackoverflow.com/questions/51452334
复制相似问题