-3

Let's say that we create the following table:

CREATE TABLE example (
    a integer,
    b integer,
    c integer,
    PRIMARY KEY (a, c)
);

Obviously the compination of a and c has to be unique. But do a and c have to be unique themselves?

Orestis
  • 7
  • 2

1 Answers1

3

No they don't have to be unique separately. Only pairs should be unique.

Example:

a, c
1, 3
2, 3
2, 1
2, 1  -- this will cause unique key violation

INSERT INTO example(a,b,c) VALUES (1,2,3),(2,2,3),(2,3,1);

DBFiddle Demo

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275