I am trying to conceptualize a database layout and I have a “theory” question. I have a system that has for example:
- users
- books
The books are not unique, for instance Alice, Bob, and Carl can all have a copy of Moby Dick. Also, each user can have many books. This is a simple many-to-many relationship that I understand pretty well. However, where would I store information about Alice’s specific copy of Moby Dick?
I eventually want to be able to do the following:
– find all users who have a copy of Moby Dick
– change the information about an individual “instances” of a book :Alice’s copy of Moby Dick is “loaned out”
– change/add information for a book (i.e. everyone’s copies): Add publisher info to Moby Dick.
I can’t see how to efficiently lay this out. I could have 1 table of books, 1 table of users, and then n tables for n users, each containing information about his/her collection. This seems like it will be slow when I need to find every one with a copy of Moby Dick. Any suggestions would be helpful.
Assuming that it is a library database, I would start with the below design.
Tables:
This table structure allows,
For a better understanding here is some pseudo SQL code.
I think the above query explains the table structure, you can add attributes like date published to book copies, or information about the author on books, some date fields on user book loans for tracking the periods that use