0

我只是不明白为什么在创建此表时出现语法错误:

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;

给我:

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

看起来它给我的日期时间带来了麻烦,但为什么呢?我已经在另一个表中使用了它并且它正在工作。

谢谢。

4

2 回答 2

4

STARTING是保留关键字,应该用反引号转义,

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;
于 2013-01-03T15:10:06.697 回答
1

开始是保留关键字。也许你可以使用不同的。

于 2013-01-03T15:11:04.533 回答