使用引用两个外键的复合主键创建表

时间:2012-12-05 16:06:07

标签: mysql database

我正在尝试使用MySQL创建下表:

CREATE TABLE registrations (
    eventNumber CHAR(3) UNIQUE NOT NULL
        CHECK (EXISTS (SELECT eventNumber FROM events)),
    employeeNumber CHAR(5) UNIQUE NOT NULL 
        CHECK (EXISTS (SELECT employeeNumber FROM employees)),

    PRIMARY KEY(eventNumber , employeeNumber ),

    FOREIGN KEY (eventNumber) REFERENCES eventNumber (employees)
        ON UPDATE RESTRICT 
        ON DELETE RESTRICT,
    FOREIGN KEY (employeeNumber ) REFERENCES employeeNumber(employees)
        ON UPDATE RESTRICT 
        ON DELETE RESTRICT  
) ENGINE=InnoDB;

然而,当我运行命令时,我得到一个无法创建表错误(1005)。这可能会出现什么问题?

1 个答案:

答案 0 :(得分:1)

作为参考,我得到了REFERENCES语句错误。

事实上它应该是:

REFERENCES <table name>(<attribute name>)