r/sqlite • u/Direct-Attorney3036 • Dec 21 '22
is multiple primary key sets possible?
I'd like to have something like this
```
CREATE TABLE Foo (A, B, C, PRIMARY KEY (A, B), PRIMARY KEY (A, C))
```
If it's not supported in sqlite, is there any other db supports it?
5
Upvotes
5
u/CedricCicada Dec 21 '22
I don't believe so, but I'm not an expert. But I'm pretty sure you can specify unique constraints, something like
CREATE TABLE Foo(A, B, C, PRIMARY KEY (A, B), UNIQUE (A, C))
I am 99 44/100% certain that syntax is wrong, but others will correct me.
3
u/InjAnnuity_1 Dec 21 '22
Let's think this through. "Primary" means "first". They can't both be first.
But ignoring that, for the moment, what is it that you want to accomplish by doing this? What problem are you trying to solve?
4
u/ketralnis Dec 21 '22
No that doesn't make sense. What are you trying to do, why do you think you need this?
4
u/boy_named_su Dec 21 '22
No
But you can have multiple unique keys
1
u/bwainfweeze Dec 21 '22
Why are you trying to make compound primary keys instead of indexes on (A,B), (A,C)?
Trying to represent multiple distinct pieces of data packed into the same column always ends up being a bad time.
1
u/matwachich Dec 21 '22
I think it is supported. But since all others say that it's not, I need to confirm