I have multiple (composite) primary keys on a table and one of them will be auto increment. However, interestingly SQLite allows usage of AUTOINCREMENT
keyword
UNIQUE INDEX
alone doesn't have the same effect as PRIMARY KEY
. A unique index will allow a NULL; a primary key constraint won't. You're better off declaring both those constraints.
CREATE TABLE ticket (
id INTEGER PRIMARY KEY AUTOINCREMENT,
seat TEXT NOT NULL,
payment INTEGER,
UNIQUE (id, seat));
You should also think hard about whether you really need to accept NULL payments.