MySQL 报错:Error Code: 1264. Out of range value for column ‘final‘ at row 5
初学MySQL,总是遇到各种各样的问题,今天在练习用子查询更新数据时,报错Error Code: 1264. Out of range value for column 'final' at row 5。
use teaching;
#将student表中入学成绩低于800的所有学生的期末成绩增加5%
update score set final=final*1.05
where studentno in (select studentno from student where entrance<800);
#报错
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 and reconnect
原来是Workbench设置为安全更新模式。要禁用安全模式,打开首选项-> SQL Editor

在Safe Updates前面打钩,重新打开Workbench。
重新运行代码发现仍然报错:
Error Code: 1264. Out of range value for column 'final' at row 5
#在第5行,列'final'的值超出范围
原来是final数据类型为float(3,1),数值最大为99.9,更新后的final超出范围,所以报错。修改数据类型或者修改更新条件就可以正常运行啦~