SQLite multi-Primary Key on a Table, one of them is Auto Increment

前端 未结 4 1201
难免孤独
难免孤独 2020-12-08 15:48

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

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 16:23

    No, I don't think this is possible.

    You can create a UNIQUE INDEX which has essentially the same effect as a PRIMARY KEY:

    CREATE UNIQUE INDEX pk_index ON "table1"("field1","field2");
    

    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.

提交回复
热议问题