奇怪!明明创建表时设置的字段为NOT NULL,但下面这种方式仍能插入成功呢?
mysql> show create table t \G
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`a` varchar(10) NOT NULL,
`b` varchar(10) NOT NULL,
`c` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> insert into t(a) values('1') ;
Query OK, 1 row affected, 2 warnings (0.11 sec)
mysql> select * from t;
+---+---+---+
| a | b | c |
+---+---+---+
| 1 | | 0 |
+---+---+---+
1 row in set (0.01 sec)
mysql版本为:
mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.5.40-0ubuntu0.14.04.1 |
+-------------------------+
但上述语句在mysql5.6.17版本中执行时就会报错。 另外在
5.5.40-0ubuntu0.14.04.1中若显式指定NULL就不行了。如
下所示:
mysql> insert into t(a,b) values('1',null) ;
ERROR 1048 (23000): Column 'b' cannot be null
可有人知道原因?如何使得在5.5.40中执行第一条语句时也报错呢?