• 0

Database - which method is better?


Question

I am designing a database structure for a simple solution, and am being suggested to change my existing layout. I have argued my layout is "cleaner" but being told I have needless tables...

Say I have a product table. I also need to store long text fields of description and internal_review.

My way involves a main product table, with a table each for description and internal_review, both joining against a common product_id field.

The way being suggested is as above, but with a single product_texts table, with a field for description and a field for internal_review, again joining on product_id.

Does anyone have any feelings either way on this?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Why would you just not have...

  • Product
    • id
    • description
    • internal_review

Are you expecting more than one description and internal review per product?

Link to comment
Share on other sites

  • 0

In my opinion, I would say that the product_description field probably belongs in the "products" table, assuming that there's one description for each product (Joining on a 1-to-1 relationship is needlessly expensive). If you do need to have it in a separate table, your way works better since using their way you'd end up duplicating data, which is bad.

However, your method requires two joins, as opposed to their method which only requires one join. So from a performance perspective, their method is better, but I'd go with your method since storage is less available than performance these days.

EDIT: Since you changed the design, if your products will only have a single review, why not just store the whole lot in the "products" table and reap the benefits of epic performance? :)

Link to comment
Share on other sites

  • 0

Issue them with the smackdown buddy, unless they pay your wages or money for a job you are doing for them, then do it their way and gloat at them afterwards when they are using an inflexible system.

Link to comment
Share on other sites

  • 0

The reason I have the descriptions in a separate table, is that I'd always been taught to keep TEXT fields separate from anything else and then link to them via JOIN?

Am I wrong on this? I don't mind changing it at all.

Link to comment
Share on other sites

  • 0
The reason I have the descriptions in a separate table, is that I'd always been taught to keep TEXT fields separate from anything else and then link to them via JOIN?

Am I wrong on this? I don't mind changing it at all.

To be fair, I avoided databases as a topic at uni, so you might be right. However, in terms of performance, I'd store it all in one table. Joins are expensive, and if the site gets a lot of traffic you'd get much faster responses from the database by storing it all in a single table.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.