• 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?

I think I just like the clean separation, but can see benefit in the suggested way as far as efficiency goes...

post-21654-1259064049_thumb.png

Link to comment
https://www.neowin.net/forum/topic/848726-database-which-method-is-better/
Share on other sites

20 answers to this question

Recommended Posts

  • 0

urm, the second way is how i would do it, i wouldnt want two tables for things of the same nature.

the entire ethos of a database is to group together things of a similar nature - plus it means less table creates....

also you have kinda answered your question by having a SQL select next to them - the suggestion is clearly more simple

  • 0

its not just efficiency, its good practice. it may well be that you know its never going to change, but what if it did and you needed to expaned to:

store multiple reviews

add new long text fields

yada yada

its going to get real messy real fast if you have a table per field. the idea of a datbase table is to have records for entity avaliable, if you had to expand what the db did at some point it would be very bad to have to write 100 joins for each extra bit of information.

as i said that might not be relevant.

what is it for can i ask?

  • 0

Cheers bud! As far as reviews go, this is an internal review - we test each product and write a review. It is a one to one relationship.

When it comes to user reviews, that will be a one to many, so I will give that it's own table for sure.

  • 0

Why give user reviews their own table? Just use the same review table again, and have a tinyint field to flag rather or not it's a user review (1) or not (0)?

Cheers bud! As far as reviews go, this is an internal review - we test each product and write a review. It is a one to one relationship.

When it comes to user reviews, that will be a one to many, so I will give that it's own table for sure.

  • 0

I would still put them in the same table, and just put the user id in that table but allow it to be null. For that matter, you can then make the assumption that if the user id is null, it is your internal review, and you don't even need the tinyint field.

Ah.. sorry, I was going about this from the stand point of "My Way", not the suggested way that you are leaning toward. You are right, with the suggested way it just wouldn't make sense, because you would potentially be duplicating other information needlessly :)

Will a product ever have more than one description? If not, the way I would personally do this is to move the description into the main products table, and then have a single review table that will hold both user reviews and staff reviews.

Edited by Drakja
  • 0

Simply put, if there will ever by multiple reviews then your way is better. If there will only ever be a single review per product, which I suspect could be the case as I notice you actually referred to the field as internal_review, then their way is better.

With multiple reviews, your way would eliminate having a blank or redundant description field for every review row. That is better, because redundancy is a dangerous to data integrity (which is the most important aspect of database design).

However, with only single reviews per product, your suggestion would effectively be referred to as vertical partitioning, and it will make your system slower, not more efficient. In fact if this was the case then I would eliminate additional tables altogether, because I'm pretty sure a product is only ever going to have one description, too.

Joins are not fast, joins are slow. Selecting from a single table is much faster and if you structure your statements properly -- that is, specify the columns you want explicitly instead of using "SELECT *" -- then there should be no overhead from additional columns at all.

  • 0

My reasoning for is in an external table is because it is a TEXT field, and I'd always been taught that having a TEXT field within a table of other types was a slow way to use a database, and that bumping them off to another table was preferable and then joining.

Am I wrong? I don't hold on to any of my database knowledge with any unproven convictions and am happy to relearn.

  • 0

I've never used this approach, and can't really see the benefits to be honest. A join is going to slow the query down, even if it's by a small fraaction of a second. I don't think you are really going to gain anything by putting text fields in their own table. Rather they are in their own table or the same table as the product, you are still going to have to access them, might as well be in one table so that you don't have the extra overhead of opening another :)

Also another thing to remember from a db-admin prespective is indexes. In one table, the DBMS only needs to keep up with one index, the primary key. Split into two just for moving text fields into their own table, it now has to keep up with the primary key on the products table, the primary key on the description table, and the foreign key back to the product table.

My reasoning for is in an external table is because it is a TEXT field, and I'd always been taught that having a TEXT field within a table of other types was a slow way to use a database, and that bumping them off to another table was preferable and then joining.

Am I wrong? I don't hold on to any of my database knowledge with any unproven convictions and am happy to relearn.

  • 0
Simply put, if there will ever by multiple reviews then your way is better. If there will only ever be a single review per product, which I suspect could be the case as I notice you actually referred to the field as internal_review, then their way is better.

With multiple reviews, your way would eliminate having a blank or redundant description field for every review row. That is better, because redundancy is a dangerous to data integrity (which is the most important aspect of database design).

However, with only single reviews per product, your suggestion would effectively be referred to as vertical partitioning, and it will make your system slower, not more efficient. In fact if this was the case then I would eliminate additional tables altogether, because I'm pretty sure a product is only ever going to have one description, too.

Joins are not fast, joins are slow. Selecting from a single table is much faster and if you structure your statements properly -- that is, specify the columns you want explicitly instead of using "SELECT *" -- then there should be no overhead from additional columns at all.

+1

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

    • No registered users viewing this page.
  • Posts

    • Sorry to be that guy but, Given Trump won again even after a failed first term it would appear attacking the other side is how to gain Government in America. Voters when it came down to it didn't give a s**t about those Democratic achievements and voted for Trump over an intelligent, qualified mixed race woman. We need to face up to this uncomfortable reality. There are more Americacan voters who support racism and christian bigotry along with defending and supporting pedophilia, adjudicated rapists, multiple time convicted felons etc than those who don't. Btw, that is how the world sees America now. Not that Trump voters care as they attempt to cocoon themselves in a white supremacy bubble.
    • That's not clickbait. Clickbait is headlines like, "You'll never guess what this person looks like now" for example. For goodness sake, take a look around the internet if you think this is clickbait. How do sites survive if people don't click through to articles? How many people in all honesty would have clicked this if it had your suggested headline? You and those upvoting your post won't be happy until the web is a couple of hundred websites all behind a paywall.
    • HopToDesk 1.46.2.0 by Razvan Serea HopToDesk aims to improve the user experience by providing a free, easy-to-use, and secure remote desktop solution for all major device types including Windows PC, Mac, Linux, Android, Chrome Books, iOS, and even Raspberry Pi devices. HopToDesk empowers you to connect, control, and collaborate with ease. Whether you're providing IT support, managing remote teams, or accessing your own devices from anywhere, HopToDesk offers a reliable and secure solution. HopToDesk does not and cannot monitor user activity as the application uses end-to-end encryption for all traffic, and does not make a distinction between personal and business use (both are allowed). Additionally, HopToDesk includes many of the main features of common remote desktop solutions such as Unattended Access, File Transfer, Live Chat, Wake-On-LAN, 2FA, Direct IP access, a Recent Session and Favorite list, and is available in over 20 languages. HopToDesk can run in portable mode or installed on desktop operating systems. Installation is optional, and will install the HopToDesk service which runs in the background and listens for incoming connections, allowing the device to be accessible at all times. Why Choose HopToDesk? Completely Free: Enjoy full access for both personal and commercial use—no hidden fees or limitations. End-to-End Encryption: All communications, including screen sharing, file transfers, and chats, are protected with robust encryption. Open Source: Contribute to and benefit from a transparent and community-driven project. No Account Required: Connect instantly without the need for sign-ups or subscriptions. Core Features Remote Control & Screen Sharing: Effortlessly access and manage remote devices. File Transfer: Securely send and receive files with drag-and-drop simplicity. Live Chat: Communicate in real-time during sessions. Multi-Monitor Support: Navigate multiple screens with ease. Clipboard Synchronization: Copy and paste seamlessly across devices. Wake-on-LAN: Power on remote systems remotely. Session Recording: Document sessions for future reference. Two-Factor Authentication: Enhance security with an additional verification layer. Custom Branding: Personalize your remote sessions with custom avatars. Unattended Access: Connect to devices without requiring user intervention. Network Customization: Adjust settings like TURN relays and signaling servers to suit your environment. Centralized Device Management Utilize the HopToDesk Dashboard to: Monitor device status in real-time. Generate invite links for easy device integration. Customize network settings and synchronize changes effortlessly. Add a personal touch with custom avatars displayed during remote sessions. Download: HopToDesk 64-bit | HopToDesk 32-bit | ~9.0 MB (Freeware) Download: HopToDesk ARM64 | 21.4 MB Link: HopToDesk Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Or use Epic games and get full games for free. lol Steam and their demos. Thankfully there’s competition
  • Recent Achievements

    • Reacting Well
      Almohandis earned a badge
      Reacting Well
    • First Post
      Cosminus earned a badge
      First Post
    • One Year In
      ThatGuyOnline earned a badge
      One Year In
    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      478
    2. 2
      +Edouard
      181
    3. 3
      PsYcHoKiLLa
      119
    4. 4
      Steven P.
      84
    5. 5
      neufuse
      73
  • Tell a friend

    Love Neowin? Tell a friend!