sql >> データベース >  >> RDS >> PostgreSQL

データベース設計-null許容フィールド

    高度に正規化された1つのオプションは、テーブルをより似たものにすることです

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

    ここで、エントリは、特定の通知の関連する(ユーザー/会社/グループ)通知テーブルにのみ存在します。

    (外部キーがオプションであることを示している状況では、null許容外部キーに問題はないと思いますが、同様のタイプの複数の外部キーは、非正規化されたデザインの印象を与えます)




    1. PostgreSQLで選択したクエリのフィールドに基づいて重複する行を削除しますか?

    2. COALESCEとISNULLのどちらが速いですか?

    3. Microsoft SQL Server でのデータベースの削除と再作成

    4. SQL Serverエージェントジョブの変更(T-SQL)