Product Attributes - How to design tables?

Last post 07-04-2009 1:49 PM by TATWORTH. 7 replies.

Sort Posts:

  • Product Attributes - How to design tables?

    07-02-2009, 10:24 PM
    • Member
      89 point Member
    • saburius
    • Member since 07-12-2008, 7:37 PM
    • Posts 212

    Hello, I'm working on an e-commerce site and I need to create product attributes that can be assigned to products.  I'm only poking around in the dark as I'm not sure how it should be done but the following is what I have:

    Product Table, ProductAttributes Table, ProductsWithAttributes Table.

    - The product table just list the products.

    - The ProductAttributes table allows the creation of reusable attributes like color, size, weight etc. (any number of attribute labels with a short decription - optional).

    - The ProductsWithAttributes table list the ProductID, AttributeID, AttributeValue, and AttributePrice.

    Am I going in the right direction with this? I need to design a flexible Attribute system that can be applicable no matter what the store sells. Any ideas or suggestions are welcome.


    Thank you!

  • Re: Product Attributes - How to design tables?

    07-03-2009, 1:27 AM
    • Participant
      1,768 point Participant
    • nmreddy83
    • Member since 01-21-2009, 6:00 PM
    • India
    • Posts 316

    how about database load.. i feel it is better to use FileSystem and Database togeather.

    Like Filesystem for Master Settings and Database to get the coredata.

    or you can desingn your database carefully also... i see some drawback in your design..

    like tagging Attribute and WithAttribute places.. in long run it may increase complexity

    ***Hope this helps you***
    ***Please mark as answer if this helps you. ***

    thank you,
    -nm reddy
  • Re: Product Attributes - How to design tables?

    07-03-2009, 2:06 AM
    • Contributor
      4,930 point Contributor
    • RickNZ
    • Member since 01-01-2009, 8:43 AM
    • Nelson, New Zealand
    • Posts 826

    The scenario you've described is often a good fit for an XML column.  That should also allow you to combine your three tables into one.  One advantage of XML is that it allows recursive properties (properties on properties).

  • Re: Product Attributes - How to design tables?

    07-03-2009, 3:28 AM
    • All-Star
      17,710 point All-Star
    • vivek_iit
    • Member since 06-18-2006, 6:13 PM
    • New Delhi
    • Posts 3,171
    • TrustedFriends-MVPs

    saburius:
    Am I going in the right direction with this? I need to design a flexible Attribute system that can be applicable no matter what the store sells. Any ideas or suggestions are welcome.

    Yes the design is fine, because you have normalized the tables correctly. This is a good solution for handling many-to-many relationships in the data model. One column which you can add is IsActive (to activate/de-activate the fields).

    HTH,

    Vivek

    CodeASP.NET Community

    Please mark the most helpful reply/replies as "Answer".
  • Re: Product Attributes - How to design tables?

    07-03-2009, 3:33 PM
    • Member
      89 point Member
    • saburius
    • Member since 07-12-2008, 7:37 PM
    • Posts 212

    Thank you for all the responses. One of the problems I've realized is the rlationship between the attributes table and the products with attributes table. What happens if an attribute is deleted? Are the attributes that are referenced in productswithattributes become orphaned? I quite confused on this. Also, what is the difference between product attributes and product variants?

    It would be awesome to see some kind of article or example of the architecture and methodology.

    Thank you!

  • Re: Product Attributes - How to design tables?

    07-03-2009, 3:58 PM
    Answer
    • All-Star
      17,710 point All-Star
    • vivek_iit
    • Member since 06-18-2006, 6:13 PM
    • New Delhi
    • Posts 3,171
    • TrustedFriends-MVPs

    saburius:
    Thank you for all the responses. One of the problems I've realized is the rlationship between the attributes table and the products with attributes table. What happens if an attribute is deleted? Are the attributes that are referenced in productswithattributes become orphaned?

    If an attribute related to some product(s) is selected for deletion, you should notify the user with something like "The selected attribute has associations with some products, deleting it will delete those associations also. Press OK to go ahead, else select Cancel".

    If the user selects Ok, then you need to delete all associations in the mapper cross table.

    saburius:
    Also, what is the difference between product attributes and product variants?

    Attributes are like properties of a product, where was a product variant can be another type of product, like a Honda SUV and a Sedan are both variants of Honda, but might have same attributes like Color (black).

    HTH,

    Vivek

    CodeASP.NET Community

    Please mark the most helpful reply/replies as "Answer".
  • Re: Product Attributes - How to design tables?

    07-03-2009, 6:36 PM
    Answer
    • Contributor
      3,196 point Contributor
    • DigiMortal
    • Member since 01-10-2007, 7:22 PM
    • Tallinn, Estonia
    • Posts 562
    • TrustedFriends-MVPs

    saburius:

    Thank you for all the responses. One of the problems I've realized is the rlationship between the attributes table and the products with attributes table. What happens if an attribute is deleted?

    I think that if there is at least one sale for product with specific attribute you shouldn't allow deletion of this product. I'm almost sure that users of you e-commerce site can see their shopping history. If you show attributes there you have to be sure that you don't change the data that user once accepted before paying.

    Don't forget to mark solution providing post as "Answered".
    It helps others to find correct solutions!

    Also visit my ASP.NET blog!
  • Re: Product Attributes - How to design tables?

    07-04-2009, 1:49 PM
    Answer
    • All-Star
      62,278 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 8:34 AM
    • England
    • Posts 12,144
    • TrustedFriends-MVPs

    Which version of SQL Server are you using?

    You might like to look at versioning the Product table by splitting it into a ProductRoot, ProductLeaf so that once a ProductLeaf is referenced by an OrderLine then any attempt to change a referenced ProductLeaf causes a new Leaf to made. Once the changes to the new Leaf are complete then the new Leaf is activated and the old deactivated.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Page 1 of 1 (8 items)