PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Datenbankdesign – Nullable-Felder

Eine stark normalisierte Option besteht darin, die Tabellen ähnlicher zu machen

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

wobei Einträge nur in der relevanten (Benutzer/Unternehmen/Gruppe)Benachrichtigungstabelle für eine bestimmte Benachrichtigung vorhanden sind.

(Ich glaube nicht, dass mit nullbaren Fremdschlüsseln etwas falsch ist, wenn dies anzeigt, dass der Fremdschlüssel optional ist, aber mehrere Fremdschlüssel ähnlichen Typs den Eindruck eines denormalisierten Designs erwecken)