CREATE TABLE titlexplan(
id INTEGER NOT NULL,
title_id INTEGER NOT NULL ,
plan_id INTEGER NOT NULL ,
start_date DATETIME NOT NULL,
end_date DATETIME
CHECK (start_date < end_date),
PRIMARY KEY(id),
INDEX (title_id),
FOREIGN KEY (title_id)
REFERENCES title(id)
INDEX (plan_id),
FOREIGN KEY (plan_id)
REFERENCES plan(id)
);
這是我正在使用的代碼,並且出現語法錯誤:#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 'INDEX (plan_id), FOREIGN KEY (plan_id) REFERENCES plan(id))' at line 10
。我應該索引一個外鍵?我應該使用這張表的主鍵嗎?
我試圖讓title_id和plan_id更新,當其他表中的相應ID更新時,我試圖跟蹤更改。
我一直無法找到一個明確的指導如何做到這一點,這些查詢部分工作,但不是全部。我不認爲我在這張表中需要一個主鍵,但是當我不使用主鍵時,我得到一個警告:「Warning, table contains no primary key
」。所以,我只是添加了'id'列。不過,我並不認爲這是真正需要的。
請指教。
謝謝。
你得到的錯誤是因爲mssing逗號:'參考資料標題(ID),' –