是 5NF 关系的 6NF relvar 表中所需的主键。考虑以下设置:
-- The 5NF table
CREATE TABLE party_address(
address_id int NOT NULL,
party_id int NOT NULL,
-- some other columns
PRIMARY KEY (address_id, party_id)
);
CREATE TABLE party_address_is_billing(
address_id int NOT NULL,
party_id int NOT NULL,
value boolean NOT NULL,
transaction_time tstzrange NOT NULL DEFAULT tstzrange(CURRENT_TIMESTAMP, NULL, '[)'),
EXCLUDE USING GIST (address_id WITH =, party_id WITH =, transaction_time WITH &&)
);
是否需要PRIMARY KEY
在party_address_is_billing
表上显式声明?由于排除约束指定了唯一标识符 ( (address_id, party_id, transaction_time)
),因此显式指定 似乎是多余的PRIMARY KEY (address_id, party_id, transaction_time)
。它还会创建一个额外的和不必要的索引。
- 不在表上指定的后果是什么
PRIMARY KEY
?