I have a table where I have information about each asset I have (Laptop, Screen, Desktop, Scanners, etc..). I also have another table where I have custom column for each asset (so for a specific desktop I can have a custom column called “Color”)… quick shematic :
Assets Table
AssetID Description
---------------------------
1 Desktop HP79801
Assets Custom Column
AssetID Column1 Column2
-----------------------------------
1 Color BluRay ?
Now I want to store the value for each column. The way I currently do it for each unit is :
AssetID UnitID Column1 Column2
-----------------------------------
1 1 Blue Yes
1 2 Blue No
1 3 Black No
1 4 Blue Yes
Now my question, is there a more efficent way to do this and how can I increase the number of column to infinity in an efficent way also ? Is it possible ?
In the end, how to store custom product attributes with effecienty ?
In short, yes.
What you have there isn’t scalable in the slightest. What you want is to have a table for your assets, a table for the custom parameters and a “link” table. Then, enter multiple values into your link table rather than multiple columns.
As an example:
Assets Table
Attributes Column
Link table
If your attributes are all model specific though, you may also want to add a
AssetIdcolumn to your assets custom column, but I wouldn’t personally do that unless none of your assets at all shared attributes.You may also want to tag this further. You may want to annotate your attributes table with a data type, and maybe have another table related to the attributes table holding the possible data values, then, in your link table, insert the ID of the entry from the aforementioned table.