Database Design for Inventory

I am starting to design a typical product based MySQL database but I keep running in circles on how to design the tables.

I have many types of products

  • Jeans
  • Tshirts
  • Dresses

Which have many of the same attributes

  • Size
  • Price
  • Colour

But some of the products have specific attributes, like length or logo or package.

Do I make a separate table for every product even though many of the columns are the same, or do I make a general product table and then have some sub-tables for specific products?

3

Do not make a table for every product.

This problem has been solved many ways. Try this:

Make a product (or products) table, put your common product attributes in the product table, then make an attribute table and a productattribute table, something like:

attribute
---------
attributeId
attributeName
attributeDescription


productattribute
----------------
productId
attributeId
attributeValue

Then you can assign arbitrary attributes to your products.

You can take the schema a little further if you like, using:

attribute
---------
attributeId
attributeName
attributeDescription
attributeType // [float, int, varchar, etc.]


productAttribute
----------------
productId
attributeId
attributeValueFloat
attributeValueInt
attributeValueVarChar

This technique complicates your schema a bit, so be aware of what you are getting into if you decide to use the extra columns to store values by data type.

An alternative that might just suit your needs a little better would be to use a NoSQL Store like MongoDB for your products. Then you can store the attributes you need for each type of product without resorting to the complexity of a relational database schema.

One approach would be to design your database similar to how you would define a class hierarchy, where you define base table(s) (classes) that provide the common attributes, and then you add additional tables that provide specific attributes to extend the table to the specific products.

Define a base product table

create table Products_base as
    id
    item
    brand
    model
    description
    size
    color
    price #more about this later

Define additional tables for products that differ substantially

create table pants as
    base #foreign key to base product
    waist
    length
    material
    style

create table dress as
    base #foreign key to base product table
    waist
    hemlength
    bust
    material
    belt

Another approach would be to define the base product table, and then define an attributes table, and provide the attributes for each additional product,

create table Products_base as
    id autoincrement
    item
    brand
    model
    description
    size
    color
    price #more about this later

create table attributes as
    id autoincrement
    name
    description

create table product_+attributes as
    product_id #product.id
    attribute_id #attributes.id
    value

Using pants as an example, you would want to add attributes to pants (add to the attributes table)

"length", "length of item"
"inseam", "length of inseam"
"style", "style of article" #example, "jeans"
#etc

And then you would add values for the attributes

product.id("pants"), attribute.id("inseam"), "32in"
product.id("pants"), attribute.id("waist"), "34in"
product.id("pants"), attribute.id("style"), "jeans"
product.id("dress"), attribute.id("style"), "sundress"
#etc

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Database Design for Inventory

I am starting to design a typical product based MySQL database but I keep running in circles on how to design the tables.

I have many types of products

  • Jeans
  • Tshirts
  • Dresses

Which have many of the same attributes

  • Size
  • Price
  • Colour

But some of the products have specific attributes, like length or logo or package.

Do I make a separate table for every product even though many of the columns are the same, or do I make a general product table and then have some sub-tables for specific products?

3

Do not make a table for every product.

This problem has been solved many ways. Try this:

Make a product (or products) table, put your common product attributes in the product table, then make an attribute table and a productattribute table, something like:

attribute
---------
attributeId
attributeName
attributeDescription


productattribute
----------------
productId
attributeId
attributeValue

Then you can assign arbitrary attributes to your products.

You can take the schema a little further if you like, using:

attribute
---------
attributeId
attributeName
attributeDescription
attributeType // [float, int, varchar, etc.]


productAttribute
----------------
productId
attributeId
attributeValueFloat
attributeValueInt
attributeValueVarChar

This technique complicates your schema a bit, so be aware of what you are getting into if you decide to use the extra columns to store values by data type.

An alternative that might just suit your needs a little better would be to use a NoSQL Store like MongoDB for your products. Then you can store the attributes you need for each type of product without resorting to the complexity of a relational database schema.

One approach would be to design your database similar to how you would define a class hierarchy, where you define base table(s) (classes) that provide the common attributes, and then you add additional tables that provide specific attributes to extend the table to the specific products.

Define a base product table

create table Products_base as
    id
    item
    brand
    model
    description
    size
    color
    price #more about this later

Define additional tables for products that differ substantially

create table pants as
    base #foreign key to base product
    waist
    length
    material
    style

create table dress as
    base #foreign key to base product table
    waist
    hemlength
    bust
    material
    belt

Another approach would be to define the base product table, and then define an attributes table, and provide the attributes for each additional product,

create table Products_base as
    id autoincrement
    item
    brand
    model
    description
    size
    color
    price #more about this later

create table attributes as
    id autoincrement
    name
    description

create table product_+attributes as
    product_id #product.id
    attribute_id #attributes.id
    value

Using pants as an example, you would want to add attributes to pants (add to the attributes table)

"length", "length of item"
"inseam", "length of inseam"
"style", "style of article" #example, "jeans"
#etc

And then you would add values for the attributes

product.id("pants"), attribute.id("inseam"), "32in"
product.id("pants"), attribute.id("waist"), "34in"
product.id("pants"), attribute.id("style"), "jeans"
product.id("dress"), attribute.id("style"), "sundress"
#etc

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật