英文:
MariaDB ERROR 4161 (HY000): Unknown Data Type
问题
在尝试创建具有外键的表时,我遇到了未知数据类型错误。我不确定我的语法是否有问题?确切的错误消息是:ERROR 4161 (HY000) 第14行:未知数据类型:“t_name”,这意味着错误发生在P1_Player表中。
DROP TABLE IF EXISTS P1_Player;
DROP TABLE IF EXISTS P1_Plays;
DROP TABLE IF EXISTS P1_Coach;
DROP TABLE IF EXISTS P1_Game;
DROP TABLE IF EXISTS P1_Team;
创建表P1_Team
(t_name varchar(20),
primary key (t_name)
);
创建表P1_Player
(fname varchar(20),
lname varchar(20),
DOB date,
jersey_# int,
t_name varchar(20),
primary key (fname, lname, DOB),
foreign key (t_name) references P1_Team (t_name)
on delete cascade
);
创建表P1_Coach
(fname varchar(20),
lname varchar(20),
t_name varchar(20),
foreign key (t_name) references P1_Team (t_name)
on delete cascade
);
创建表P1_Game
(t_name varchar(20),
game_date date,
game_time time,
primary key (t_name, game_date, game_time),
foreign key (t_name) references P1_Team (t_name)
on delete cascade
);
创建表P1_Plays
(t_name varchar(20),
game_date date,
game_time time,
primary key (t_name, game_date, game_time),
foreign key (t_name, game_date, game_time) references P1_Game (t_name, game_date, game_time)
on delete cascade
);
英文:
Getting an unknown data type error when I try to create tables with a foreign key. I am not sure if my syntax is wrong? The exact error message is: ERROR 4161 (HY000) at line 14: Unknown data type: 't_name', meaning the P1_Player table is where the error is being thrown.
DROP TABLE IF EXISTS P1_Player;
DROP TABLE IF EXISTS P1_Plays;
DROP TABLE IF EXISTS P1_Coach;
DROP TABLE IF EXISTS P1_Game;
DROP TABLE IF EXISTS P1_Team;
create table P1_Team
(t_name varchar(20),
primary key (t_name)
);
create table P1_Player
(fname varchar(20),
lname varchar(20),
DOB date,
jersey_# int,
t_name varchar(20),
primary key (fname, lname, DOB),
foreign key (t_name) references P1_Team (t_name)
on delete cascade
);
create table P1_Coach
(fname varchar(20),
lname varchar(20),
t_name varchar(20),
foreign key (t_name) references P1_Team (t_name)
on delete cascade
);
create table P1_Game
(t_name varchar(20),
game_date date,
game_time time,
primary key (t_name, game_date, game_time),
foreign key (t_name) references P1_Team (t_name)
on delete cascade
);
create table P1_Plays
(t_name varchar(20),
game_date date,
game_time time,
primary key (t_name, game_date, game_time),
foreign key (t_name, game_date, game_time) references P1_Game (t_name, game_date, game_time)
on delete cascade
);
答案1
得分: 1
The error is in jersey_#
on create table P1_Player
you should use the back-quote (`) if you want to use special characters in mysql/mariadb column names :
错误出现在 jersey_#
在 create table P1_Player
中,如果你想在 mysql/mariadb 列名中使用特殊字符,应该使用反引号 (`):
create table P1_Player
(fname varchar(20),
lname varchar(20),
DOB date,
jersey_#
int,
t_name varchar(20),
primary key (fname, lname, DOB),
foreign key (t_name) references P1_Team (t_name)
on delete cascade
);
英文:
The error is in jersey_#
on create table P1_Player
you should use the back-quote (`) if you want to use special characters in mysql/mariadb column names :
create table P1_Player
(fname varchar(20),
lname varchar(20),
DOB date,
`jersey_#` int,
t_name varchar(20),
primary key (fname, lname, DOB),
foreign key (t_name) references P1_Team (t_name)
on delete cascade
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论