miahmiah900
Programmer
hello... i wondering how to design a database that needs to be flexible. it is not a simple case of "i know the fields that will be needed, lets make columns for them", but rather there may be 0 or many different columns in a given table... what i want to know is the best way to design a database like this, and how to write queries for selecting data from them.
any comments or pointers to good database design resources would be greatly appreciated
let me explain in a little more detail an example situation. i want to know if there is a better/easier way to do this...
take the example of a product database that could potentially have 4 tables: tbl_product, tbl_option_name, tbl_option_data, tbl_option_key, and tbl_inventory.
tbl_product stores names, descriptions and image paths related to each product (a candle, for example). tbl_option_name has different types of options associated with a product (candle color or size). tbl_option_data contains the various choices for an option (red, tall). tbl_inventory keeps track of distinct types of inventory and their current quantity, of which there can be 1 or many for each type of product. tbl_option_key associates particular choices of options with an entry in tbl_inventory.
with this design, i can create unlimited number of options for a product, with unlimited number of choices for each option. thus i can describe virtually any type of product and make it available for sale to customers as a single product with choices for customizing it rather than a collection of many similar products.
but, is it efficient? to use this design, i had to write multiple queries to find all the information regarding a single product (although maybe with the new versions of mysql and subqueries it would be possible). also, i cannot figure out a way using an sql query alone to find a particular entry in tbl_inventory when given only a tbl_product id and option id's (from tbl_option_name and tbl_option_data).
what i have had to do is write some php code with some loops to discover which inventory is being described by the options that have been selected.
thanks for reading!
- miah
p.s. i know oscommerce is available for use, but i am posing this as more of a question in database design and not as seeking help with the development of an actual application.
any comments or pointers to good database design resources would be greatly appreciated
let me explain in a little more detail an example situation. i want to know if there is a better/easier way to do this...
take the example of a product database that could potentially have 4 tables: tbl_product, tbl_option_name, tbl_option_data, tbl_option_key, and tbl_inventory.
tbl_product stores names, descriptions and image paths related to each product (a candle, for example). tbl_option_name has different types of options associated with a product (candle color or size). tbl_option_data contains the various choices for an option (red, tall). tbl_inventory keeps track of distinct types of inventory and their current quantity, of which there can be 1 or many for each type of product. tbl_option_key associates particular choices of options with an entry in tbl_inventory.
with this design, i can create unlimited number of options for a product, with unlimited number of choices for each option. thus i can describe virtually any type of product and make it available for sale to customers as a single product with choices for customizing it rather than a collection of many similar products.
but, is it efficient? to use this design, i had to write multiple queries to find all the information regarding a single product (although maybe with the new versions of mysql and subqueries it would be possible). also, i cannot figure out a way using an sql query alone to find a particular entry in tbl_inventory when given only a tbl_product id and option id's (from tbl_option_name and tbl_option_data).
what i have had to do is write some php code with some loops to discover which inventory is being described by the options that have been selected.
thanks for reading!
- miah
p.s. i know oscommerce is available for use, but i am posing this as more of a question in database design and not as seeking help with the development of an actual application.