Reputation: 1202
I would like to make a primary key in a SQLite table made of two columns which work like this:
id1
, id2
, value
id1
id2
id1
and id2
I read a lot but all question I found told how to make two independent primary keys, but it is not my case.
Upvotes: 0
Views: 246
Reputation:
Yes, you can do this.
sqlite> create table t (f1 integer, f2 integer);
sqlite> create unique index i12 on t (f1, f2);
sqlite> .schema
CREATE TABLE t (f1 integer, f2 integer);
CREATE UNIQUE INDEX i12 on t (f1, f2);
sqlite> insert into t values (1,2);
sqlite> insert into t values (1,3);
sqlite> insert into t values (2,2);
sqlite> insert into t values (1,2);
Error: columns f1, f2 are not unique
See the reference of CREATE INDEX
.
Upvotes: 2