I would suggest you to have two tables:
bookStores:
id
name
someMoreColumns
books:
id
bookStore_id
title
isbn
date
publisher
format
size
someMoreColumns
It's easy to see the relationship here: a bookStore
has many books
.
Pay attention that I'm putting all the columns you have in all of your BookStore
tables in just one table, even if some row from some table does not have a value to some column.
Why I prefer this way:
1) To all the data from BookStore
tables, just few columns will never have a value on table books
(as example, size
and format
if you don't have an e-book version). The other columns can be filled someday (you can set a date
to your e-books, but you don't have this column on your table BookStore_Bar
, which seems to refer to the e-books). This way you can have much more detailed infos from all your books if someday you want to update it.
2) If you have a bunch of tables BookStore
, lets say 12, you will not be able to handle your data easily. What I say is, if you want to run some query to all your books (which means to all your tables), you will have at least three ways:
First: run manually the query to each of the 12 tables and so merge the data;
Second: write a query with 12 joins or set 12 tables on your FROM
clause to query all your data;
Third: be dependent of some script, stored procedure or software to do for you the first or the second way I just said;
I like to be able to work with my data as easy as possible and with no dependence of some other script or software, unless I really need it.
3) As of MySQL (because I know much more of MySQL) you can use partitions
on your table books
. It is a high level of data management in which you can distribute the data from your table to several files on your disk instead of just one, as generally a table is allocated. It is very useful when handling a large ammount of data in a same table and it speeds up queries based on your data distribution plan. Lets see an example:
Lets say you already have 12 distinct bookStores, but under my database model. For each row in your table books
you'll have an association to one of the 12 bookStore. If you partition your data over the bookStore_id
it will be almost the same as you had 12 tables, because you can create a partition for each bookStore_id
and so each partition will handle only the related data (the data that match the bookStore_id
).
Lets say you want to query the table books
to the bookStore_id
in (1, 4, 9). If your query really just need of these three partitions to give you the desired output, then the others will not be queried and it will be as fast as you were querying each separated table.
You can drop a partition and the other will not be affected. You can add new partitions to handle new bookStores. You can subpartition a partition. You can merge two partitions. In a nutshell, you can turn your single table books
in an easy-to-handle, multi-storage table.
Side Effects:
1) I don't know all of table partitioning, so it's good to refer to the documentation to learn all important points to create and manage it.
2) Take care of data with regular backups (dumps) as you probably may have a very populated table books
.
I hope it helps you!