gpt4 book ai didi

mySQL:尝试创建外键时出错

转载 作者:行者123 更新时间:2023-11-29 20:13:32 26 4
gpt4 key购买 nike

我正在尝试创建两个共享公共(public)列的表。这些表目前为空,因为我想在所有数据正确链接后添加数据。我似乎无法弄清楚语法错误的根源。我可以毫无问题地创建表“publisher”,但无法引用它的主键“publishername”作为下一个表的外键。

我得到了可怕的E

RROR 1064 "near 'references publisher(publishername))' at line 1".

我迷路了,因为我之前使用过类似的语法来执行此操作。非常感谢!


create table publisher (
publishername varchar(30) primary key,
city varchar(15),
country varchar(10),
telephone varchar(15),
yearfounded int(4));

create table book (
booknumber int(3) primary key,
bookname varchar(50),
publicationyear int(4),
pages int(4),
publishername varchar references publisher(publishername));

最佳答案

您似乎没有给出外键的长度。这很好用。您可以查看here .

create table publisher (
publishername varchar(30) primary key,
city varchar(15),
country varchar(10),
telephone varchar(15),
yearfounded int(4));

create table book (
booknumber int(3) primary key,
bookname varchar(50),
publicationyear int(4),
pages int(4),
publishername varchar(30) references publisher(publishername));

关于mySQL:尝试创建外键时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39936239/

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