MariaDB错误 4161 (HY000): 未知的数据类型

huangapple go评论53阅读模式
英文:

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
        );

huangapple
  • 本文由 发表于 2023年4月4日 17:14:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75927566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定