我正在尝试创建此表:
CREATE TABLE INFORMEPERICIAL (
INFORME_NO INT(3),
PRIMARY KEY (INFORME_NO),
DATEEMISIO DATE NOT NULL,
IMPORTCOBERT DECIMAL(8,2),
PERIT_NO INT(3) NOT NULL,
INFORME VARCHAR(200),
RESULTATPERITATGE VARCHAR(20),
CONSTRAINT RESULTATPERITATGE_CK CHECK (RESULTATPERITATGE IN ('COBERT_TOTAL','COBERT_PARCIAL','SENSE_COBERTURA','REPARAT')),
ESTATINFORME VARCHAR(20),
CONSTRAINT ESTATINFORME_CK CHECK ESTATINFORME IN ('PENDENT','TANCAT'),
CONSTRAINT INFORMEPERICIAL_FK_PERIT FOREIGN KEY (PERIT_NO) REFERENCES PERIT (NUMERO),
CONSTRAINT INFORMEPERICIAL_CK_INFORME_NO_NUM_POSITIU CHECK (INFORME_NO > 0)
);
但是,我在使用外键时遇到了麻烦。
这是我确定的“Perit”表格:
CREATE TABLE PERIT (
COGNOM1 VARCHAR(30) NOT NULL,
COGNOM2 VARCHAR(30) NOT NULL,
DATANAIX DATE NOT NULL,
NOM VARCHAR(30) NOT NULL,
NIF VARCHAR(10) NOT NULL,
LOGIN VARCHAR(50) NOT NULL,
PASSWORDMD5 VARCHAR(50) NOT NULL,
NUMERO INT(3) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (NUMERO)
);
我无法解除为什么我收到错误1005,字段类型等于!
答案 0 :(得分:1)
问题在这里:
CONSTRAINT ESTATINFORME_CK CHECK ESTATINFORME IN ('PENDENT','TANCAT'),
用括号括起条件:
CONSTRAINT ESTATINFORME_CK CHECK (ESTATINFORME IN ('PENDENT','TANCAT')),