gpt4 book ai didi

java - 创建外键的语法错误

转载 作者:行者123 更新时间:2023-11-29 00:00:18 24 4
gpt4 key购买 nike

我正在尝试创建以下表格设计,但我在下面收到此错误如何为 arrivaltimes 表中的 stops 表设置外键?

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 REFERENCES stops(stop_id) )' at line 4

stt.execute("CREATE TABLE IF NOT EXISTS stops"
+ "(stop_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, "
+ " name varchar(30) NOT NULL, " + " route INT(11) NOT NULL, "
+ " lat double(10,6) NOT NULL, "
+ " longi double(10,6)NOT NULL) ");

stt.execute("CREATE TABLE IF NOT EXISTS arrivaltimes(id INT(11) NOT NULL PRIMARY KEY,"
+ " weekday VARCHAR(20) NOT NULL,"
+ "arrivaltime time NOT NULL,"
+ " stop_id INT FOREIGN KEY REFERENCES stops(stop_id) )" );

最佳答案

改变

stop_id INT FOREIGN KEY REFERENCES stops(stop_id)

stop_id INT, FOREIGN KEY fk_stop_id(stop_id) REFERENCES stops(stop_id)

关于java - 创建外键的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30132136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com