复合主键属性必须是唯一的吗?

Do composite primary key attributes have to be unique?

假设我们创建以下 table:

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

显然 a 和 c 的组合必须是唯一的。但是 a 和 c 本身必须是唯一的吗?

不,它们不必分别是唯一的。只有对应该是唯一的。

示例:

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