防止MySQL将隐式默认值插入非空列 [英] Preventing MySQL from inserting implicit default values into not null columns
本文介绍了防止MySQL将隐式默认值插入非空列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用多个插入(在一个语句中),我有这个表结构
CREATE TABLE Scores
(
studentID varchar(50)not null,
score int
)
ENGINE = InnoDB
我的查询:
INSERT INTO Scores Values
',45),
(NULL,41),
('Jones',53)
此语句(我预期)应该失败,因为[StudentID]列不接受NULL。
问题是MySQL将空字符串('')插入行2 ...并允许其余的继续。
解决方案
问题:
SET SQL_MODE ='STRICT_ALL_TABLES'
或放
SQL_MODE ='STRICT_ALL_TABLES'
到
my cnf
(然后重新启动MySQL
)。I am trying to use multiple inserts (in one statement) and I have this table structure
CREATE TABLE Scores ( studentID varchar(50) not null, score int ) ENGINE = InnoDB
My Query:
INSERT INTO Scores Values ('Barry', 45), (NULL, 41), ('Jones', 53)
This statement (I expected) should fail since [StudentID] column does not accept NULL. The problem was MySQL inserted empty string ('') into row 2... and allow the rest to continue.
解决方案Issue:
SET SQL_MODE='STRICT_ALL_TABLES'
or put
SQL_MODE='STRICT_ALL_TABLES'
under
[mysqld]
intomy.cnf
(then restartMySQL
).这篇关于防止MySQL将隐式默认值插入非空列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文