Search code examples
sqlitesyntax-errorcreate-table

Error in SQLite CREATE query


A dumb question, but I can't find a error here...

CREATE TABLE units (_id INTEGER PRIMARY KEY AUTOINCREMENT, group_id INTEGER NOT NULL, unit_name STRING NOT NULL UNIQUE (group_id, unit_name))

SQLite says:

SQLiteManager: Likely SQL syntax error: CREATE TABLE units (_id INTEGER PRIMARY KEY AUTOINCREMENT, group_id INTEGER NOT NULL, unit_name STRING NOT NULL UNIQUE (group_id, unit_name))
 [ near "(": syntax error ]
Exception Name: NS_ERROR_FAILURE
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)  [mozIStorageConnection.createStatement]

What is the error?


Solution

  • My guess would be missing comma before UNIQUE:

    CREATE TABLE units (
        _id INTEGER PRIMARY KEY AUTOINCREMENT,
        group_id INTEGER NOT NULL,
        unit_name STRING NOT NULL,
        UNIQUE (group_id, unit_name)
    )