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

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

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

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

所有的标识符,不管是什么类型的资源,都是这种格式,一个资源可以有多个标识符。那么,是在同一个表中指定 resourceType 和 ID 和 ll 标识符更好,还是应该为每个资源使用不同的标识符表?

例如,如果我有 3 个资源类型,“患者”、“从业者”和“组织”,每个资源类型大致如下:


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.