您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

数据库设计-可为空的字段

数据库设计-可为空的字段

高度标准化的一种选择是使表更像

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
);

其中条目仅存在于任何给定通知的相关(用户/公司/组)通知表中。

(在表示外键是可选的情况下,我认为可空外键没有任何问题,但是类似类型的多个外键确实给人以非规范化设计的印象)

其他 2022/1/1 18:50:57 有327人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶