简体   繁体   中英

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;

Order是SQL中的保留字,为您的表选择一个不同的名称。

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM