red_sky33
red_sky33

Reputation: 13

Mysql giving me a syntax error when trying to create a table. I can't find where this error is

So when trying to create this table the console returns a syntax error that I just can't figure out.

CREATE TABLE Photobook( PhotoID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
                        filepath VARCHAR(30) NULL, desc VARCHAR(500) NOT NULL);

this returns

ERROR 1064 (42000): 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 'desc VARCHAR(500) NOT NULL)' at line 1

Upvotes: 1

Views: 45

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175566

Quote reserved word DESC with backticks:

Nonreserved keywords are permitted as identifiers without quoting. Reserved words are permitted as identifiers if you quote them.

CREATE TABLE Photobook( PhotoID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
                       filepath VARCHAR(30) NULL, `desc` VARCHAR(500) NOT NULL);

SqlFiddleDemo

or change column name to description

Upvotes: 1

Related Questions