Nathan English
Nathan English

Reputation: 784

MySQL - CREATE TABLE - Syntax Error - Error 1064

I have been looking at the below sql script for ages now and I can't see the problem! It's getting error 1064 - which could be anything...

CREATE TABLE order (order_no INTEGER NOT NULL AUTO_INCREMENT,
                vat_id INTEGER NOT NULL,
                order_status VARCHAR(30) NOT NULL,
                order_pick_date DATE,
                order_ship_from INTEGER NOT NULL,
                employee_id INTEGER NOT NULL,
                payment_id INTEGER,
                PRIMARY KEY (order_no))
        ENGINE = MYISAM;

Upvotes: 1

Views: 112

Answers (3)

Uours
Uours

Reputation: 2492

As others have already pointed , the reserved word order is the issue .

However if you need to , you can still use it by enclosing with backticks / backquotes :

`order`

The corrected SQL statement ( which worked for me in MySQL 5.5.24 ) is :

CREATE TABLE
`order`
(
     order_no INTEGER NOT NULL AUTO_INCREMENT
    ,vat_id INTEGER NOT NULL
    ,order_status VARCHAR(30) NOT NULL
    ,order_pick_date DATE
    ,order_ship_from INTEGER NOT NULL
    ,employee_id INTEGER NOT NULL
    ,payment_id INTEGER
    ,PRIMARY KEY (order_no)
)
ENGINE = MYISAM;

Upvotes: 1

Matt
Matt

Reputation: 90

The problem is that you are trying to create a table using a reserved name. If you change the table name to 'orders' then it will work.

Have a look at https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html for the full list of reserved words.

Upvotes: 1

BrianAtkins
BrianAtkins

Reputation: 1349

Order is a reserved word in SQL, pick a different name for your table.

Upvotes: 1

Related Questions