0

I've recently started getting (somewhat serious with MySQL and databases in general and naturally I am still slightly green when it comes to some of the basic concepts in contrast to how I'm used to doing things in programming languages.

Let's assume I have this table tableBooks and another table tableBoxes and I am looking to store the books that are inside a given box.

In coding, I'd just stick references to the box instances into an array within box and call it a day.

With databases, however, I assume I can't store references to all bookss, rather I have a key in tableBoxes (let's call this Container) that holds the foreign key of the appropriate tableBoxes item.

Is this correct or am I out on the wrong limb?

I am asking because this bottom-up approach seems wasteful to a novice such as myself, e.g., to get all the books in a specific box, I'd have to go through all the books and check if their Container value corresponds to the currently selected box. What if there are thousands of boxes and tens of thousands books?

Thanks in advance and apologies for what probably is an inane question.

Phil Strahl
  • 165
  • 1
  • 1
  • 8
  • Possible duplicate of [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) – philipxy Mar 01 '18 at 05:33
  • Hi. Time to read a book on information modeling, the relational model & database design. (You just need a table BookBox.) PS This is a faq. As with every question, please google many clear, concise, specific versions/variants/phrasings of your question/problem/goal/desiderata with & without your specific strings/names/code and read many answers from many questions, which should inform your further googling. If you don't find an answer after applying what you learned and repeating this then ask a question. Use the most frequently productive keywords as tags. Use the best search as a title. – philipxy Mar 01 '18 at 05:34

0 Answers0