Search code examples
phpmysqllamp

unit of messurement table is required if there i'm going to store two record in database


In my e-commerce application there are several products available in two units i.e. product "X" has two types of packaging

  1. 200 gram
  2. 400 gram

Is there any need for creating Unit_Of_Mesurement table? If not then what is the solution or is there any other solution?


Solution

  • For an e-commerce site where a given product may be sold in different packages, you can either have each product package stored as a separate product, or use a second table to store the different formats of the product, where the rest of the generic product info is taken from a main product table.

    For example, you'd have a product table, that contains information that applies to the product regardless of which format is being considered:

    ID | name      | brand
    --------------------------
     1 | Product 1 | ACME Corp
     2 | product 2 | ACME Corp
    

    And then you'd have a product_format table, which contains the different packaging variations that product might have. If a product isn't sold in any different formats, then you could just have a single row here that contains the price, without specifying the format, since you won't need to show that information.

    ID | product_ID | format | price
    ----------------------------------
     1 | 1          | 200g   | 19.99
     2 | 1          | 400g   | 37.99
     3 | 2          | null   | 8.99