为什么MySQL允许将NOT NULL列更新为NULL? [英] Why does MySQL allow to update a NOT NULL column to NULL?
问题描述
我正在ubuntu 10.10
中运行MySql
.我创建了一个名为'employee'
的表,该表具有3个字段名称 empno,名称和薪金.插入了几个实体.在此过程的中间,我想将薪金属性更改为'NOT NULL'
.我将表更改为
I'm running MySql
in ubuntu 10.10
. I created a table called 'employee'
having 3 field names empno, name and salary. Inserted few entities. In the middle of the process i want to change salary attribute as 'NOT NULL'
. I Alter the table as
ALTER TABLE employee MODIFY salary int(10) NOT NULL;
查询已执行.我想通过使用命令进行测试,
Query executed. I wanted to test by using command,
UPDATE employee SET salary=NULL;
Query OK, 15 rows affected, 15 warnings (0.06 sec)
Rows matched: 15 Changed: 15 Warnings: 15
还给出了警告" (Code 1048): Column 'salary' cannot be null "
(每行重复)
also gave warnings " (Code 1048): Column 'salary' cannot be null "
(Repeated for every row)
但是当我看到我的桌子时,所有工资都是零('0'
).
But when i saw my table , All salaries were Zeros('0'
).
在WINDOWS XP的MySql中,相同的查询导致错误而不是警告
我同时检查了INNODB和MYISAM引擎,但结果相同. 请帮助我了解处理之外发生的情况.
I checked in both INNODB and MYISAM engines but same Result. Please help me to know what happened beside processing.
推荐答案
对于Ubuntu安装,您不得将SQL_MODE
设置为严格".
You must not have SQL_MODE
set to strict on you ubuntu installation.
问题
SET SQL_MODE='STRICT_ALL_TABLES'
或添加
SQL_MODE='STRICT_ALL_TABLES'
到 这篇关于为什么MySQL允许将NOT NULL列更新为NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!Ubuntu
上的my.cnf
.