0

I just can't understand why I'm having a syntax error on this table creation:

CREATE TABLE IF NOT EXISTS Tasks (
ID INT UNSIGNED NOT NULL auto_increment,
Name VARCHAR(255) DEFAULT '' NOT NULL,
Description TEXT,
Date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Status ENUM('New', 'Assigned', 'In Progress', 'On Hold', 'Done', 'Canceled'),
Priority ENUM('Urgent', 'High', 'Normal', 'Low'),
Creator SMALLINT UNSIGNED DEFAULT '0' NOT NULL,
Assignee SMALLINT UNSIGNED,
Starting DATETIME,
Deadline DATETIME,
Completion DATETIME,
PRIMARY KEY(ID)
) ENGINE = INNODB;

Gives me:

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 
'Starting DATETIME,
Deadline DATETIME,
Completion DATETIME,
PRIMARY KEY(ID)
) ENG' at line 10

Looks like its giving me trouble with datetime but why? I've used this in another table and it's working.

Thanks.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
SrgHartman
  • 651
  • 2
  • 8
  • 23

2 Answers2

4

STARTING is a reserved keyword, It should be escape with backtick,

CREATE TABLE IF NOT EXISTS Tasks 
(
    ID INT UNSIGNED NOT NULL auto_increment,
    Name VARCHAR(255) DEFAULT '' NOT NULL,
    Description TEXT,
    Date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    Status ENUM('New', 'Assigned', 'In Progress', 'On Hold', 'Done', 'Canceled'),
    Priority ENUM('Urgent', 'High', 'Normal', 'Low'),
    Creator SMALLINT UNSIGNED DEFAULT '0' NOT NULL,
    Assignee SMALLINT UNSIGNED,
    `Starting` DATETIME,
    Deadline DATETIME,
    Completion DATETIME,
    PRIMARY KEY(ID)
) ENGINE = INNODB;
John Woo
  • 258,903
  • 69
  • 498
  • 492
  • The full list of reserved words is here: http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html – BenLanc Jan 03 '13 at 15:12
1

Starting is a reserved keyword. Perhaps you could use a different one.

TJ-
  • 14,085
  • 12
  • 59
  • 90