Search code examples
libreofficelibreoffice-base

LibreOffice Error "1: Unexpected token: UNQUE in statement"


I ran this SQL command

CREATE TABLE TEST(
    KEY char(10) UNIQUE NOT NULL,

    PRIMARY KEY(KEY)
);

and it gave me this error:

2: Unexpected token: UNIQUE in statement [CREATE TABLE TEST(
KEY char(10) UNIQUE]

I'm just trying to create a simple table from SQL command. This is the error I got, which it seems to be strange, because this would run perfectly on MS access.

Anyway to fix this?

//EDIT

Due to "Key" is restricted word in SQL, I gave it another try.

CREATE TABLE TEST(
    MLP char(10) UNIQUE NOT NULL,

    PRIMARY KEY(MLP)
);

However, it seems to got broken again.

 5: Unexpected token: UNIQUE in statement [CREATE TABLE TEST(
MLP char(10) UNIQUE]

Solution

  • KEY is a reserved word in SQL. Choose another name for your column and it should work fine.

    The official tutorial uses the following syntax:

    CREATE TABLE TEST(
        MLP CHAR(10) NOT NULL PRIMARY KEY
    );