2014-02-21 88 views
0

四處錯誤:FOREIGN KEY MySQL錯誤

 
#1064 - 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 'FOREIGN KEY (Epost) REFERENCES KUNDE (Epost)) ENGINE = INNODB' at line 9 

這是代碼:

CREATE TABLE ORDRE (
    OrdreNr INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
    Dato DATE, 
    Antall INT, 
    Pris INT, 
    PNr INT, 
    Epost VARCHAR(32), 
    FOREIGN KEY (PNr) REFERENCES PRODUKT (PNr) 
    FOREIGN KEY (Epost) REFERENCES KUNDE (Epost) 
    ) ENGINE = INNODB; 

問題是什麼問題?

回答

0

您忘記逗號

Epost VARCHAR(32), 
FOREIGN KEY (PNr) REFERENCES PRODUKT (PNr), 
              ^---you forgot this comma 
FOREIGN KEY (Epost) REFERENCES KUNDE (Epost) 
0

試試這個:

CREATE TABLE ORDRE (
    OrdreNr INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
    Dato DATE, 
    Antall INT, 
    Pris INT, 
    PNr INT, 
    Epost VARCHAR(32), 
    FOREIGN KEY (PNr) REFERENCES PRODUKT (PNr), 
    FOREIGN KEY (Epost) REFERENCES KUNDE (Epost) 
    ) ENGINE = INNODB; 

有一個逗號丟失。