I’ve covered some strange default behavior around nulls in MySQL. There’s another nuance to this issue: you can still insert rows without specifying values for not null columns. MySQL will helpfully give you a default value (this is not really helpful – true help would be a quick failure with a descriptive error message). Let’s walk through this example.
mysql> Create Table NullTable (a Int Not Null, b Int Not Null); Query OK, 0 rows affected (0.01 sec)
Here’s a table with two not null columns.
mysql> Insert Into NullTable (a) Values (1); Query OK, 1 row affected, 1 warning (0.01 sec)
We can totally insert, even though we didn’t specify a value for b and b is not null.
mysql> Show Warnings; +---------+------+----------------------------------------+ | Level | Code | Message …[Read more]