Search code examples
mysqlcreate-tableunique-key

Syntax error on UNIQUE KEY when creating a table


I am trying to create a tabe in a database using the code below. However, it's not working, and I can't figure out why.

The error being generated is a syntax error on 'UNIQUE KEY ID (ID)', but according to the tutorial I'm using (and the docs I can find), that looks ok.

I've also tried 'UNIQUE ID (ID)' and 'UNIQUE ID', but I still get the syntax error.

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);

Can anybody please tell me what I am doing wrong? Thanks.


Solution

  • It should be inside the braces

    google_maps text(256) COLLATE latin1_general_ci,
    UNIQUE KEY ID (ID)
    );