Search code examples
mysqlsyntaxmysql-error-1064ddl

MySQL CREATE TABLE 'You have an error in your SQL syntax' error


I am pulling my hair out over this. I have connected to a MySQL server and am trying to create a table on it:

CREATE TABLE order (
    order_id INT,
    order_is_overnight BIT,
    order_quantity INT,
    order_amount DOUBLE,
    order_timestamp DATETIME
);

When I run this I get:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order (
        order_id INT,
        order_is_overnight BIT,
        order_quantity INT,
        order_amou' at line 1
SQLState:  42000
ErrorCode: 1064

This is the world's vaguest error message, akin to a Java exception that says "Whoops, something went wrong somewhere in your code!"

Any ideas where I'm going awry?! I have checked, and rechecked, and rechecked and this seems to be a perfectly valid/legal CREATE TABLE statement (don't worry about performance, indexes, keys, etc.; this is just a dummy/test table).


Solution

  • order is an reserved word, you must enclose it name in back quotes

    CREATE TABLE `order` (
        order_id INT,
        order_is_overnight BIT,
        order_quantity INT,
        order_amount DOUBLE,
        order_timestamp DATETIME
    );