简体   繁体   中英

MySQL DDL error creating tables

I am attempting to create tables for a MySQL database, but I am having some syntactical issues. It would seem that syntax checking is behaving differently between tables for some reason. While I've gotten all the other tables to go through, the table, 'stock' doesn't seem to be working, despite seeming to use the same syntax patterns.

    CREATE TABLE users (
        user_id             SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
        username            VARCHAR(30) NOT NULL,
        password            CHAR(41) NOT NULL,
        date_joined         DATETIME NOT NULL,
        funds               DOUBLE UNSIGNED NOT NULL,

        PRIMARY KEY(user_id),
        UNIQUE KEY(username)
    );

    CREATE TABLE owned_stocks (
        id                  SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
        user_id             SMALLINT UNSIGNED NOT NULL,
        paid_price          DOUBLE UNSIGNED NOT NULL,
        quantity            MEDIUMINT UNSIGNED NOT NULL,
        purchase_date       DATETIME NOT NULL,

        PRIMARY KEY(id)
    );

    CREATE TABLE tracking_stocks (
        ticker              VARCHAR(5) NOT NULL,
        user_id             SMALLINT UNSIGNED NOT NULL,

        PRIMARY KEY(ticker)
    );

    CREATE TABLE stocks (
        ticker              VARCHAR(5) NOT NULL,
        last                DOUBLE UNSIGNED NOT NULL,
        high                DOUBLE UNSIGNED NOT NULL,
        low                 DOUBLE UNSIGNED NOT NULL,
        company_name        VARCHAR(30) NOT NULL,
        last_updated        INT UNSIGNED NOT NULL,
        change              DOUBLE NOT NULL,
        percent_change      DOUBLE NOT NULL,

        PRIMARY KEY(ticker)
    );

Am I just missing a really obvious syntactical issue?

ERROR:

#1064 - 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 'change DOUBLE NOT NULL, percent_change DOUBLE NOT NULL, last
DOUBLE' at line 4

The 'stocks' field name 'change' is a reserved mysql word. Try replacing it with a different field name?

For reference: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

because change is a Reserved Word, escape it using backtick

`change` DOUBLE NOT NULL,

MySQL Reserved Word List

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