I’m looking for some advice as to which direction to head in re the design of a product database and the best methods for storing / retrieving data from it. The block I’m hitting is in how to best represent the various (valid) options that a product may have.
The basic structure is (not actual table definitions):
PRODUCT_TABLE {
ID(int),
NAME(varchar),
AVAILABLEOPTIONS(varchar),
etc...
}
COLOROPTIONS_TABLE {
ID(int),
COLORNAME(varchare),
etc...
}
BODYOPTIONS_TABLE {
ID,
BODYNAME,
etc...
}
What would be the best way to store a value in the AVAILABLEOPTIONS field that would allow me to specify the OPTIONS tables and the ID’s within those tables that the product is available in. (i.e. A product might not be available with all the options in a particular option table)
I’ve done a bunch of research (mainly on this great site) and looked at JSON, serialising values, multidimensional arrays etc, but I’m not sure the best way to go.
In the end, the AVAILABLEOPTIONS value will be used to display the options on a product page or used to construct a form for a user to generate a valid product code. I’ll also be trying to setup an input form that allows an admin to generate the availableoptions value for storage in the DB.
Any tips or thoughts would be greatly appreciated!
I’m not sure if this is the right place to put this update, but here goes.
Have done more research and it seems the storage of multiple values in a single field is a definite no-no. I’m not sure the EAV model is right for my needs either. But when it comes to normalising the database requirements I have, I’m not sure I’ve got it figured out yet. I’ve come up with this:
Image Here: http://dev.aqualux.com.au/images/1.png
(Wouldn’t let me post an image in the edit because I’m too new here…)
Where pid/oid in the orange tables are foreign keys. The issue I’m not grasping is that any given product can have multiple options of a given type, or none at all….
Thanks
Have you thought of creating an additional table to act like a bridge? Recently, I built a database to store Adobe Captivate results in MSSQL. One of the requirements was to create a unique student based off the employee and their department. This alone, was three tables where I used the bridge as my identifier for the individual assessments.
I’ve posted snippets from my blog below. Mind you that this is pulled directly from MSSQL.
So in your case, you would have an Options table
And modify your PRODUCT table so that your AVAILABLEOPTIONS is SMALLINT and the foreign key, similarly like https://stackoverflow.com/a/1545264.