这是我的表:
CREATE TABLE `loan_table` (
`ID` bigint(38) NOT NULL AUTO_INCREMENT,
`LOAN_ID` bigint(38) DEFAULT NULL,
`PLAN_ID` bigint(38) NOT NULL,
`EXT_LOAN_APP_ID` bigint(38) DEFAULT NULL,
`REDISTRIBUTE_TIME` datetime DEFAULT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `IDX_UN_LOAN_PLAN_APP`(`LOAN_ID`,`PLAN_ID`,`EXT_LOAN_APP_ID`,`REDISTRIBUTE_TIME`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
我在4列(LOAN_ID,PLAN_ID,EXT_LOAN_APP_ID,REDISTRIBUTE_TIME)上添加了唯一键,但我可以一次又一次地在insert sql下面执行。
INSERT INTO `loan_table` (`LOAN_ID`, `PLAN_ID`,`EXT_LOAN_APP_ID`, `REDISTRIBUTE_TIME`)
VALUES
( 435870, 0, 2369, NULL);
答案 0 :(得分:1)
在唯一索引中,mysql将NULL视为唯一值。因此可以重复插入这些值
( 435870, 0, 2369, NULL);
使列NOT NULL和DEFAULT为空字符串。