1

我正在尝试使用下面的代码在数据库中创建一个表。但是,它不起作用,我不知道为什么。

生成的错误是语法错误'UNIQUE KEY ID (ID)',但根据我正在使用的教程(以及我可以找到的文档),这看起来不错。

我也试过'UNIQUE ID (ID)'and 'UNIQUE ID',但我仍然得到语法错误。

CREATE TABLE wp_offices (
    ID smallint(3) NOT NULL AUTO_INCREMENT,
    office_created_by smallint(3) DEFAULT "0",
    office_created_date datetime DEFAULT "0000-00-00 00:00:00" NOT NULL,
    office_last_edited_by smallint(3) DEFAULT "0",
    office_last_edited_date datetime DEFAULT "0000-00-00 00:00:00" NOT NULL,
    office_name tinytext COLLATE latin1_general_ci,
    address_1 tinytext COLLATE latin1_general_ci,
    address_2 tinytext COLLATE latin1_general_ci,
    town tinytext COLLATE latin1_general_ci,
    county tinytext COLLATE latin1_general_ci,
    postcode tinytext COLLATE latin1_general_ci,
    telephone tinytext COLLATE latin1_general_ci,
    fax tinytext COLLATE latin1_general_ci,
    dx tinytext COLLATE latin1_general_ci,
    email tinytext COLLATE latin1_general_ci,
    google_maps text(256) COLLATE latin1_general_ci
)
UNIQUE KEY ID (ID);

谁能告诉我我做错了什么?谢谢。

4

2 回答 2

4

它应该在大括号内

google_maps text(256) COLLATE latin1_general_ci,
UNIQUE KEY ID (ID)
);
于 2012-12-13T15:06:57.363 回答
2

创建表的代码将是

   CREATE TABLE wp_offices(
    ID SMALLINT( 3 ) NOT NULL AUTO_INCREMENT ,
    office_created_by SMALLINT( 3 ) DEFAULT "0",
    office_created_date DATETIME DEFAULT "0000-00-00 00:00:00" NOT NULL ,
    office_last_edited_by SMALLINT( 3 ) DEFAULT "0",
    office_last_edited_date DATETIME DEFAULT "0000-00-00 00:00:00" NOT NULL ,
    office_name TINYTEXT COLLATE latin1_general_ci,
    address_1 TINYTEXT COLLATE latin1_general_ci,
    address_2 TINYTEXT COLLATE latin1_general_ci,
    town TINYTEXT COLLATE latin1_general_ci,
    county TINYTEXT COLLATE latin1_general_ci,
    postcode TINYTEXT COLLATE latin1_general_ci,
    telephone TINYTEXT COLLATE latin1_general_ci,
    fax TINYTEXT COLLATE latin1_general_ci,
    dx TINYTEXT COLLATE latin1_general_ci,
    email TINYTEXT COLLATE latin1_general_ci,
    google_maps TEXT( 256 ) COLLATE latin1_general_ci,
    UNIQUE KEY ID( ID )
    );
于 2012-12-13T15:13:41.800 回答