约束条件下的mySQL语法错误

时间:2017-09-02 23:10:36

标签: mysql syntax

CREATE TABLE MARINA_SLIP
(
SLIP_ID VARCHAR(4),
MARINA_NUM VARCHAR(4),
SLIP_NUM VARCHAR(4),
LENGTH INT,
RENTAL_FEE DECIMAL(8,2),
BOAT_NAME VARCHAR(50),
BOAT_TYPE VARCHAR(50),
OWNER_NUM VARCHAR(4),
CONSTRAINT MARINA_SLIP_SLIP_ID_PK PRIMARY KEY (SLIP_ID),
CONSTRAINT MARINA_SLIP_MARINA_NUM_FK FOREIGN KEY (MARINA_NUM),
CONSTRAINT MARINA_SLIP_OWNER_NUM_FK FOREIGN KEY (OWNER_NUM) REFERENCES OWNER (OWNER_NUM)
);

错误说明:

  

错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在'附近使用。   CONSTRAINT MARINA_SLIP_OWNER_NUM_FK FOREIGN KEY(OWNER_NUM)参考所有者(O'第12行

有谁知道为什么这不起作用?

编辑:这对我来说很明显,不包括外键引用的小错误。

1 个答案:

答案 0 :(得分:1)

REFERENCES添加到CONSTRAINT MARINA_SLIP_MARINA_NUM_FK FOREIGN KEY (MARINA_NUM) 例如 CONSTRAINT MARINA_SLIP_MARINA_NUM_FK FOREIGN KEY (MARINA_NUM) REFERENCES OWNER (MARINA_NUM)