【问题标题】:Modeling publication with multiple authors belonging to multiple instutes in SQLite在 SQLite 中对属于多个机构的多个作者进行建模
【发布时间】:2026-01-24 08:15:01
【问题描述】:

我正在尝试为以下情况提出一个合理的 SQLite 数据库架构。

我有一个包含出版物的数据库。这些出版物中的每一个都有许多作者,并且这些作者中的每一个都可以属于许多不同的机构。然而,多个作者共享一个研究所是可能的。例如,出版物的作者是 Anne、Bert 和 Carl。 Anne 属于 A 和 B 学院,Bert 属于 B 和 C 学院,Carl 属于 C、D 和 E 学院。

每份出版物的作者数量应该是可变的,任何特定作者可以属于的机构数量也应该是可变的。不过,机构应该只代表一次。

现在,我正在考虑以下架构:

create table publications (
    id integer primary key autoincrement,
    ...
)

create table publication_institutes (
    id integer primary key autoincrement,
    publication_id integer references publications(id),
    ...
)

create table publication_authors (
    id integer primary key autoincrement,
    publication_id integer references publications(id),
    ...
)

create table publication_author_institute (
    id integer primary key autoincrement,
    institude_id integer references publication_institutes(id),
    author_id integer references publication_authors(id)
)

但这似乎不是最理想的。 publication_author_institute 不再引用 publications 中的 id,但将其显式放在那里似乎也关闭了。

这种情况有明确的解决办法吗?

提前致谢!

【问题讨论】:

  • 您想知道作者曾经属于哪些机构,或者他在出版特定出版物时属于哪个机构?
  • 我需要知道哪些作者属于某个特定的出版物,以及他们在出版该出版物时属于哪个机构。对于给定的出版物,多个作者可能属于同一研究所。

标签: sqlite many-to-many one-to-many foreign-key-relationship


【解决方案1】:

我会使用包含作者、出版物和研究所的架构,然后是用于作者与研究所和作者与出版物之间关系的多对多表。

例如:

author
id    name     other info (lastname, title, etc) 
 1    Anne     ...
 2    Bert     ...
 3    Carl     ...

institute
id    name    other info (address, city, state, etc)
 1      A     ...
 2      B     ...
 3      C     ...
 4      D     ...
 5      E     ...

publication
id   title            journal          year    issue
 1   How to Publish   Weekly Journal   2011      5
 2   What I Do        Monthly Mag      2013      1
 3   How Are We       Ranger Rick      2014      9

author_affiliation
id   author_id    inst_id
 1       1           1
 2       1           2
 3       2           2
 4       2           3
 5       3           3
 6       3           4
 7       3           5
 (for this table, could also use author_id-inst_id as a composite PK,
 and get rid of the id column, as in the next table)

publication_author  (here i'm using the composite PK)
pub_id    auth_id    position
  1          1          1
  1          2          2
  2          1          2
  2          3          1
  3          3          1
(position indicates order of authorship, which is important)

从长远来看,这使得数据库的维护更容易,因为从属关系的更改只需要从 author_affilitation 表中删除一条记录,而不需要对机构或作者条目进行任何更改。对于出版物,您必须同时为publication 和publication_author 输入一条记录,但它避免了处理具有多个值的列(例如publication 表中的'authors' 列)。

同样,如果您想查询某个作者的所有出版物,您可以查询publication_authors,并在publication 和author 表上进行连接。

这是我用来减少冗余并在以后查询时提供灵活性的架构。

【讨论】:

    最近更新 更多