在 MariaDB 中创建 table 时出现 SQL 语法错误
SQL syntax error while creating table in MariaDB
使用此代码在 Mariadb 中创建 table 时
CREATE TABLE classes(
ClassID SMALLINT UNSIGNED PRIMARY,
Grade TINYINT UNSIGNED,
Subject VARCHAR(20),
YearTaught YEAR
);
我遇到了这个错误。
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '
Grade TINYINT UNSIGNED,
Subject VARCHAR(20),
YearTaught YEAR
)' at line 2
而且我不知道语法有什么问题。谢谢。
您的声明中缺少关键字 KEY
,请更新
ClassID SMALLINT UNSIGNED PRIMARY,
到
ClassID SMALLINT UNSIGNED PRIMARY KEY,
您可以使用 KEY
而不是 PRIMARY KEY
,但不只是 PRIMARY
:
Use PRIMARY KEY (or just KEY) to make a column a primary key. A primary key is a special type of a unique key. There can be at most one primary key per table, and it is implicitly NOT NULL.
使用此代码在 Mariadb 中创建 table 时
CREATE TABLE classes(
ClassID SMALLINT UNSIGNED PRIMARY,
Grade TINYINT UNSIGNED,
Subject VARCHAR(20),
YearTaught YEAR
);
我遇到了这个错误。
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' Grade TINYINT UNSIGNED, Subject VARCHAR(20), YearTaught YEAR )' at line 2
而且我不知道语法有什么问题。谢谢。
您的声明中缺少关键字 KEY
,请更新
ClassID SMALLINT UNSIGNED PRIMARY,
到
ClassID SMALLINT UNSIGNED PRIMARY KEY,
您可以使用 KEY
而不是 PRIMARY KEY
,但不只是 PRIMARY
:
Use PRIMARY KEY (or just KEY) to make a column a primary key. A primary key is a special type of a unique key. There can be at most one primary key per table, and it is implicitly NOT NULL.