带外键的多表或带外键的单表到多表

问题描述 投票:0回答:0

这表明我缺乏对数据库设计原则的了解。我正在尝试创建一个数据库,我有大约 150 个表,每个表包含不同类型的“资源”。每种类型的资源都可以有一个标识符,它由一个字符串值和一个指定定义该值的系统的 url 组成。

例子:

"system": "urn:oid:0.1.2.3.4.5.6.7"
"value": "654321"

所有的标识符,不管是什么类型的资源,都是这种格式,一个资源可以有多个标识符。

因此,最好有一个单独的表来指定

resourceType
并且 ID 和 ll 标识符在同一个表中,还是我应该为每个资源使用不同的标识符表?

例如,如果我有3个

resourceTypes
Patient
Practitioner
Organization
,每个都有大致这样的格式:


create table if not exists patient 
(
    id text primary key,
    versionid int not null,
    updatedat timestamp with time zone default timezone('utc'::text, now()) not null,
    resource jsonb not null,
);

然后我将为每个资源表创建一个标识符表:

create table if not exists patientIdentifier 
(
    id text primary key,
    resourceId text not null,
    value text not null,
    system text not null,
);

或者,我可以为所有资源表使用一个标识符表:

create table if not exists patientIdentifier 
(
    id text primary key,
    resourceType text not null,
    resourceId text not null,
    value text not null,
    system text not null,
);

是否有一种结构通常优于另一种结构?

sql postgresql foreign-keys primary-key
© www.soinside.com 2019 - 2024. All rights reserved.