0

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.

2
  • 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 Commented Jul 9, 2021 at 9:26
  • 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. Commented Jul 9, 2021 at 15:33

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.