0

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.

1
  • Welcome to Stack Overflow. I've removed the irrelevant PHP tag; you should use tags to describe your question, not your project ;-) Commented Oct 2, 2013 at 11:44

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Isn't also adding a string '0' as a default value for an int bad?
@user2336873 Also, using reserved words for columns, tables or downright anything in databases is BAD. Change the column name, it will save you so much trouble later on. Really, please.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.