Reputation: 32271
I got site for selling products. In my database I have 3 tables: Users, Countries, Products.
Each user can sale his products in many countries. When clients come to visit, my site, they can choose to search for product by country and by product price( same product sold by same user can have different prices in each country).
I thought about two implementations for this:
I like my second solution more, because I think it will perform faster, for both reading and inserting, how ever it's management is hard, I will have lots of tables, and what if instead of counties I would like to use cities, I will get thousandths of tables.
Upvotes: 0
Views: 5818
Reputation: 38010
Do NOT go for the second solution. Relational databases are meant to have a fixed number of tables, and you will run into a lot of problems if you try to have a variable amount of tables in the manner you describe.
If I understood your requirements correctly, you should probably use two linked tables: one that contains user_id
and country_id
(thus telling where each user may sell products), and one that contains country_id
, product_id
, and price
(thus telling the price of each product in each country). (This assumes that a product costs the same within a country no matter who sells it.)
Upvotes: 3