Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 897227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:51:09+00:00 2026-05-15T14:51:09+00:00

For an e-shop I have Products table (id, name, price, description) Attributes table (attribute

  • 0

For an e-shop I have

  • Products table (id, name, price, description)
  • Attributes table (attribute name, attribute value, product_id_fk)

Attribute name examples include: size, color and Attribute value examples include: XL, L, red, blue.

What is the best way to store stock levels? A “Bag” product may be in stock in L / red but not in XL / red whereas it may be in stock for all sizes in blue. There may be more than 2 attributes per product.

A third table is definitely needed. I think the best way to go is to have one column per attribute and an additional column for the product_id_fk. This would mean that if a new attribute is added for whatever product, an additional column needs to be created in the Stock table

Or is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:51:09+00:00Added an answer on May 15, 2026 at 2:51 pm

    It looks as though you have a many-to-many relationship (i.e., products can have many attributes, and attributes can be associated with many products). Therefore your best design is to have a relationship table that contains the ids of both the product and the attribute.

    products (id, name, price, description)
    attributes (id, attribute name, attribute value)
    product_attribute (product_id (PK,FK), attribute_id (PK,FK)) 
    

    This works if you have a unique row for each physical item. If you don’t then you need to have something that can handle the different types of the product.

    product (id, name, price, description)
    product_type (id, product_id (FK), count)
    attributes (id, attribute name, attribute value)
    product_attribute (product_type_id (PK,FK), attribute_id (PK,FK))
    

    PK = Primary Key
    FK = Foreign Key

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 1 table Products that looks like this: ID Product Shop Color 01
I have a table called Product and a table called Shop. Each shop has
I am building an e-shop that will have configurable products. The configurable parts will
I have a resource :products in a namespace :shop, like this: namespace :shop do
I have an association, Shop habtm Products Product habtm Shops Shop belongs_to Merchant For
We have one large xslt that renders a whole shop area including products, manifacturers
I have the following problem, I'm creating functionality for ordering products for internet shop.
We currently have several underlying database tables such as Events , Shop Products ,
I have a shop with permission to read|write both orders and products. I setup
I want to build a shop in which the products have a little wizard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.