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 just after an obligatory PRIMARY KEY keyword.
My query is:
CREATE TABLE ticket (
id INTEGER PRIMARY KEY AUTOINCREMENT,
seat TEXT, payment INTEGER,
PRIMARY KEY (id, seat))
However the error is table "ticket" has more than one primary key.
Actually I can avoid other primary keys for this table. But I am coding an ORM framework (hell yeah I’m crazy) and do not want to change structure of PRIMARY KEY constraint generation for a table (because it is allowed in MySQL afaik).
Any solutions to this?
No, I don’t think this is possible.
You can create a
UNIQUE INDEXwhich has essentially the same effect as a PRIMARY KEY:Besides, I fail to see the logic of your schema, that is -> if a column is autoincrement and you don’t intend to mess with the values manually, it’s going to be unique anyway, so it makes a good simple short primary key. Why the composite? You may have good reasons to make another index on the combination of columns, though.