gpt4 book ai didi

mysql - MySql建表出错 : check the manual that corresponds to your MySQL server version for the right syntax to use near ')'

转载 作者:太空宇宙 更新时间:2023-11-03 11:22:31 25 4
gpt4 key购买 nike

我正在创建一个新数据库,当我尝试创建表 band_members 时,dbeaver 一直给我一个错误。该错误专门与以下行有关:MEMBER_NAME VARCHAR(30) NOT NULL。第一个表 band 是使用完全相同的语法创建的。

我正在为 MySql 8+ 运行 DBeaver 6.1.5

create table band(BAND_ID int not null auto_increment, 
BAND_NAME VARCHAR(30) not null, primary key(BAND_ID));

create table band_members(MEMBER_ID int not null auto_increment,
MEMBER_NAME VARCHAR(30) not null,
BAND_ID INT,
MEMBER_ROLE VARCHAR(30), primary key(MEMBER_ID), foreign key(BAND_ID));

我希望创建第二个表 band_members,但它却在标题中给出了错误。

最佳答案

通常当您在创建表中创建外键时,您会引用它的来源,所以它看起来像这样:

create table band(BAND_ID int not null auto_increment, 
BAND_NAME VARCHAR(30) not null, primary key(BAND_ID));
create table band_members(MEMBER_ID int not null auto_increment,
MEMBER_NAME VARCHAR(30) not null,
BAND_ID INT,
MEMBER_ROLE VARCHAR(30), primary key(MEMBER_ID), foreign key(BAND_ID) references band(BAND_ID));

关于mysql - MySql建表出错 : check the manual that corresponds to your MySQL server version for the right syntax to use near ')' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58194470/

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