0

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

4

2 回答 2

3

'stocks' 字段名称 'change' 是一个保留的 mysql 字。尝试用不同的字段名称替换它?

供参考:http ://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

于 2012-10-20T22:55:48.400 回答
1

因为 change 是保留字,所以使用反引号将其转义

`change` DOUBLE NOT NULL,

MySQL 保留字列表

于 2012-10-20T22:56:53.717 回答