Prevent MySQL from entering implicit defaults into non-null columns

I am trying to use multiple attachments (in one statement) and I have this table structure

CREATE TABLE Scores
(
  studentID varchar(50) not null,
  score int
)
ENGINE = InnoDB

My request:

INSERT INTO Scores Values
('Barry', 45),
(NULL, 41),
('Jones', 53)

This statement (I was expecting) should fail because the [StudentID] column is not NULL. The problem was that MySQL entered an empty string ('') in line 2 ... and allowed the rest to continue.

+5
source share
1 answer

Question:

SET SQL_MODE='STRICT_ALL_TABLES'

or place

SQL_MODE='STRICT_ALL_TABLES'

under [mysqld]in my.cnf(then restart MySQL).

+11
source

All Articles