今天在测试触发器时,触发器如下:
DELIMITER $$
create trigger addCount after insert on test.student
for each row
begin
update test.student_count set count = (select count(*) from test.student);
end$$
创建好了触发器,但是在执行插入操作时报错,查了一下,结果如下:
在mysql5中,可以设置safe mode,比如在一个更新语句中
UPDATE table_name SET bDeleted=0;执行时会错误,报:
You are using safe update mode and you tried to update a table without a WHERE clause that uses a KEY column.”
原因是在safe mode下,要强制安全点,update只能跟where了,
要取消这个限制,可以:
SET SQL_SAFE_UPDATES=0;
即可
--------------------------------------------------------------------------------------------------------------
今天删除mysql数据库中的一条记录的时候,一直不能删除,提示错误信息如下:
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that
uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect.
后来通过搜索资料,发现mysql有个叫SQL_SAFE_UPDATES的变量,为了数据库更新操作的安全性,此值默认为1,所以才会出现更新失败的情况。
下面是SQL_SAFE_UPDATES变量为0和1时的取值说明:
SQL_SAFE_UPDATES有两个取值0和1,
SQL_SAFE_UPDATES = 1时,不带where和limit条件的update和delete操作语句是无法执行的,即使是有where和limit条件但不带key column的update和delete也不能执行。
SQL_SAFE_UPDATES = 0时,update和delete操作将会顺利执行。那么很显然,此变量的默认值是1。
所以,出现1175错误的时候,可以先设置SQL_SAFE_UPDATES的值为0,然后再执行更新,例如:
SQL_SAFE_UPDATES = 0;
delete from testTable where name='张三';