今天建表时候发现报错了:
CREATE TABLE t3
(
c1
int DEFAULT NULL,
c2
int DEFAULT NULL,
c3
int NOT NULL,
c4
int DEFAULT NULL,
PRIMARY KEY (c1
,c2
,c3
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3
Error Code: 1171. All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead。 原因是:MySQL的主键索引每一个都不能为空。因为需要通过主键来聚簇数据的。
改成如下就可以了:
CREATE TABLE t3
(
c1
int NOT NULL,
c2
int NOT NULL,
c3
int NOT NULL,
c4
int DEFAULT NULL,
PRIMARY KEY (c1
,c2
,c3
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3
参考:https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html