在数据库中更新数据时报错: 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(错误及操作见截图)
1.sql: update tableName set employee_detailed_status='xx', employee_status_code='xx' where employee_detailed_status='xx'
2.通过错误提示可以看出: 当前数据库使用的是 safe update mode(安全更新模式),并且在update时where 中没有把主键当做条件。因为在该模式会导致非主键条件下无法执行update或者delete命令,因此会报错。
3.如何解决这个问题呢?
第一种方法(简单粗暴):
执行命令SET SQL_SAFE_UPDATES = 0 来修改下数据库模式,这样再去执行update语句或者delete语句即可成功。
第二种方法(投机取巧法,这种方法不一定适用于所有情况,如果这种方法不行则采用方法1):
既然在这种模式下需要将主键作为条件,那我们就将主键作为条件加到sql中,如何加呢?
那我们就分析我们的sql语句,更改后的sql如下:
update tableName set employee_detailed_status='xx', employee_status_code='xx' where employee_detailed_status='xx' and id is not null;