SQL Database with variable number of columns

前端 未结 4 913
再見小時候
再見小時候 2021-01-24 22:38

I have a newbie question about a database I am trying to create. I have a list of publications, with this general order:

UID, Author, URL, Title, Publication, start page

4条回答
  •  不知归路
    2021-01-24 23:06

    Actually your scenario is even more complicated.

    A publication can have more than one author. An author can write more than one published article or book. That is a Many-to-Many relationship.

    We always(*) represent a many-to-many with a third table, sometimes called. Bridge table. This third table, authorship, is a child table with at least two columns, both foreign keys holding the primary key from each of its parent tables, pub_ and author_ tables. We transform the Many-to-Many into a pair of One-to-Many relationships.

    By the way, this books-author scenario is the canonical example used when teaching relational database design.

    You can have additional fields on this third table. In your case, we need a priority_ column of an integer type to sort the list of primary vs secondary authors.

    Each author’s compensation fee or royalty would be additional columns on this bridge table. If you were tracking each author needing to sign a contract for their work on that publication, the authorship_ table would have a date, date-time, or boolean column contract_signed_. So you can see that the bridge table represents anything to do with one particular author’s involvement on one particular publication.

    (*) Not merely an opinion or suggestion. Relational database design is proven by entire books filled with mathematical proofs. This includes the need to break up a many to many with a third table. Relational database design is the only case of true information engineering backed by mathematical description and proofs. Search for relation (a field of mathematics), and doctors E.F. Codd and Chris Date to learn more.

提交回复
热议问题