我现在有一张表结构如下:
CREATE TABLE `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 NOT NULL,
`address` varchar(255) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=107393 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
我设置了address
字段not null
,单条插入会报值为 null,插入多条则不报错。
插入单条语句:
INSERT into user(`name`,`address`) VALUES('xx',null);
结果:
[SQL]INSERT into user(`name`,`address`) VALUES('xqq',null)
[Err] 1048 - Column 'address' cannot be null
插入多条语句:
INSERT INTO USER (`name`, `address`)
VALUES
('xqq', NULL),
('qqq', NULL)
结果:
[SQL]INSERT INTO USER (`name`, `address`)
VALUES
('xxx', NULL),
('yyy', NULL)
受影响的行: 2
时间: 0.008s
看了下表确实成功了,这是为啥呢,求大佬指点迷津。
1
robert233 2019-05-10 13:52:08 +08:00
not null,能插入 null? 我建议你再仔细看看
|