2014-02-26 88 views
0

我有一些鏈接表的麻煩。從下面的代碼 我得到一個「錯誤:附近‘BOOKNAME’語法錯誤」:鏈接表語法錯誤

CREATE TABLE word_book (
WordName TEXT(25), FOREIGN KEY (WordName) REFERENCES word (WordName) 
BookName TEXT(25), FOREIGN KEY (BookName) REFERENCES book (BookName) 
PRIMARY KEY (WordName, BookName)); 

我是能夠成功地創建表bookwordbook表包含列BookName,表word包含列WordName

回答

0

此聲明在FOREIGN KEY約束後缺少逗號。另外,SQL要求所有表約束出現在所有列之後。

要麼重新排序:

CREATE TABLE word_book (
    WordName TEXT(25), 
    BookName TEXT(25), 
    FOREIGN KEY (WordName) REFERENCES word (WordName), 
    FOREIGN KEY (BookName) REFERENCES book (BookName), 
    PRIMARY KEY (WordName, BookName) 
); 

或者使用列約束,而不是:

CREATE TABLE word_book (
    WordName TEXT(25) REFERENCES word (WordName), 
    BookName TEXT(25) REFERENCES book (BookName), 
    PRIMARY KEY (WordName, BookName) 
); 
+0

是的!很簡單!非常感謝你! – LordBudabi