外键中的mysql错误1064

时间:2014-06-17 08:36:26

标签: mysql foreign-keys

我有表电影:

CREATE TABLE Movie(
    -----
    MID INT AUTO_INCREMENT,
    PRIMARY KEY (MID) );

当我想创建表租金时,我收到以下错误:

CREATE TABLE Rent(
    ID INT AUTO_INCREMENT,
    name VARCHAR(20),
    MID INT,
    PRIMARY KEY (ID),
    FOREIGN KEY (MID) REFRENCES Movie(MID) );

错误消息:

ERROR 1064 (42000): You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'REFRENCES Movie(MID) )' at line 6

请帮助ty。

1 个答案:

答案 0 :(得分:0)

运行以下代码,它运行正常。

CREATE TABLE Rent( id int NOT NULL auto_increment, 名称VARCHAR(20), MID int, FOREIGN KEY MID(MID)REFERENCES电影(MID), PRIMARY KEY(id))