0

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]
srakrn
  • 352
  • 2
  • 16

3 Answers3

2

I'm not sure about this, but try removing the "unique" parameter. Because if you're defining MLP as the key you're implying that it is unique, but SQL takes "KEY" and "UNIQUE" as incompatibles.

Héctor E
  • 436
  • 3
  • 9
1

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
);
Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
0

try restarting the SQL server, because the exact code you provided with works perfectly fine when i try it. Also, delete any sort of coloumn with the same name as TEST in your database

CuriousPenguin
  • 87
  • 1
  • 14