sqlmariadbmariasql

MariaDB unknown syntax error. Making a simple table


I cannot find whats wrong with my single table making sql code. The 'user' that it is referencing does exist. The error I receive is:

ERROR 1064 (42000) at line 1 in file: 'project.sql': 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 'order ( id integer(11) Primary Key auto_increment, ordertyp' at line 1

here is my code for the table:

create table order (
    id          integer(11)     Primary Key auto_increment,
    ordertype   varchar(255)    not null,
    timePlaced  timestamp       not null,
    buyUser     varchar(25),
    sellUser    varchar(25),
    foreign key(buyUser) references user(username),
    foreign key(sellUser) references user(username)
);

Anything helps, just looking for a simple syntax fix, thank you!


Solution

  • You have to quote your table name if it collides with a keyword, or contains special characters:

    create table `order` (...)
    

    See: https://dev.mysql.com/doc/refman/8.0/en/keywords.html