I am very new to PHP & Mysql. I am currently working on database structure of website. I have been a keen follower of this website. I have found that many posts have discouraged use of multiple tables. Now, suppose i have a product that has about 10 pictures associated with it and about 50 reviews. Now, should I have a separate tables for pictures and reviews or should i let all of them stay in the same table ?


Please have a look at the basics of Database normalization. In a very general way, 1:N relationships usually end up being represented as 2 tables. That is, if we have several products, and each product can have several reviews, we would create two tables, one for products and another for reviews, and we would link the reviews by using a product_id key (containing the primary key of the product). Same would apply for images, assuming there is a 1:N relationship with product and not a 1:1 relationship with review.

When querying for data, we need to join both tables for obtaining full results.

Please note that sometimes a non-normal form can be used, merging several tables in one. This sacrifices maintainability (potential duplicate data problems, among others, forcing extra work outside of the database scope) for performance, but that is a question of optimisation, not design phase.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.