高度标准化的一种选择是使表更像
create table notifications(
notification_id serial primary key,
date_created timestamp not null default Now(),
title_id text not null,
message_id text not null,
icon text not null default 'logo'
);
create table usernotifications
(
notification_id integer references notifications,
user_id integer references users
);
create table groupnotifications
(
notification_id integer references notifications,
group_id integer references groups
);
create table companynotifications
(
notification_id integer references notifications,
company_id integer references companies
);
其中条目仅存在于任何给定通知的相关(用户/公司/组)通知表中。
(在表示外键是可选的情况下,我认为可空外键没有任何问题,但是类似类型的多个外键确实给人以非规范化设计的印象)