How write down to database multiple authors in simple books table?

后端 未结 4 1600
无人共我
无人共我 2021-02-04 20:24

I am wondering how should I save authors (in case where there are more than one author) in simple database.

In case one one book has one authors, everything is easy. The

4条回答
  •  悲哀的现实
    2021-02-04 20:59

    You need another table called BookAuthor, you don't need the Authors column in Books

    BookAuthor
    ------------
    BookID
    AuthorID
    

    Where the BookID references the PK (BookID) on Books and AuthorID references PK (AuthorID) on Authors

    Select b.Title, CONCAT(a.[First Name], a.[Last Name]) As AuthorName
    From Books b
    JOIN BookAuthor ba ON b.ID = ba.BookID
    JOIN Authors a ON ba.AuthorID = a.ID
    

提交回复
热议问题