0
votes

While creating a table in Mariadb with this code

CREATE TABLE classes(
    ClassID SMALLINT UNSIGNED PRIMARY,
    Grade TINYINT UNSIGNED,
    Subject VARCHAR(20),
    YearTaught YEAR
);

I got this error.

#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

And I don't know what's wrong with the syntax. Thank you.

1
ClassID SMALLINT UNSIGNED PRIMARY KEY Also, names are case-insensitive, it is more common to use snake case instead of camel case. year_taught instead of YearTaught - Raul Sauco
@RaulSauco It works now. Thank you for your help!!! - Zwe Myint Mo
glad to hear that it helped. If that solved your problem, then that comment should have been an answer, I will re-post it. if it helped you consider marking it accepted and/or up-voting it. - Raul Sauco

1 Answers

1
votes

You are missing the keyword KEY on your statement, update

ClassID SMALLINT UNSIGNED PRIMARY,

to

ClassID SMALLINT UNSIGNED PRIMARY KEY,

You could use KEY instead of PRIMARY KEY, but not just 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.

The documentation is here.