user2336873
user2336873

Reputation: 11

MySQL Syntax Error in table creation statement

This question is very straight forward. I have this MySQL error that I haven't been able to figure out, and I need some help finding it.

The full 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 'release date NOT NULL, downloads INT NOT NULL DEFAULT '0', f' at line 6

The SQLStatement:

CREATE TABLE IF NOT EXISTS sdm_downloads
    (
        id INT NOT NULL AUTO_INCREMENT,
        project INT NOT NULL DEFAULT '0',
        name VARCHAR(40) NOT NULL,
        release date NOT NULL,
        downloads INT NOT NULL DEFAULT '0',
        filename varchar(40) NOT NULL,
        filesize varchar(40) NOT NULL,
        PRIMARY KEY(id)
    )

Thanks in advance for any, and all help.

Upvotes: 0

Views: 41

Answers (1)

juergen d
juergen d

Reputation: 204894

You need to escape reserved words like release with backticks

CREATE TABLE IF NOT EXISTS sdm_downloads
(
    id INT NOT NULL AUTO_INCREMENT,
    project INT NOT NULL DEFAULT 0,
    name VARCHAR(40) NOT NULL,
    `release` date NOT NULL,
    downloads INT NOT NULL DEFAULT 0,
    filename varchar(40) NOT NULL,
    filesize varchar(40) NOT NULL,
    PRIMARY KEY(id)
)

SQLFiddle demo

Upvotes: 1

Related Questions