使用这样的表模式有什么好处:
CREATE TABLE review (
review_id SERIAL PRIMARY KEY,
account_id INT REFERENCES account(account_id) NOT NULL,
product_id INT REFERENCES product(product_id) NOT NULL,
rating SMALLINT NOT NULL,
comment TEXT,
UNIQUE (account_id, product_id)
);
或者约束本身是否应该是主键,如下所示:
CREATE TABLE review (
CONSTRAINT review_pkey (account_id, product_id) PRIMARY KEY,
account_id INT REFERENCES account(account_id) NOT NULL,
product_id INT REFERENCES product(product_id) NOT NULL,
rating SMALLINT NOT NULL,
comment TEXT,
);