SQL Database with variable number of columns

前端 未结 4 911
再見小時候
再見小時候 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 22:54

    Database model

    You basically need a many-to-many relationship between Authors and Publications, since one author can write many publications, and one publication can be written by more than one author.

    This require you to have 3 tables.

    • Author - general info about every author (without publications_id)
    • Publication - general info about every publication (without author_id)
    • AuthorPublication - columns author_id and publication_id that are references to tables Author and Publication.

    This way you're not binding a specific author to a publication, but you can have more of them, and the same thing the other way around.

    Additional notes

    If you would like to distinguish authors' role in particular publication you could also add some column like id_role that would be a reference to a dictionary table stating all possible roles for an author. This way you could differ between leading authors, co-authors etc. This way you could also store information about people handling translation of the book, but perhaps you should then change the naming of Author to something less specific.

    Order of appearance

    You can ensure a proper ordering of your authors by adding a column in AuthorPublication which you would increment separately for every Publication. This way you would be able to preserve the ordering as you need it.

提交回复
热议问题