I have a question concerning the modeling of my database.
I have a simple database containing items/systems (see example below)
There is a main table with the system id, name, description, and a couple of other fields/attributes for each system.
Each system can be of a certain "system type" (for example a server, a router, an encryptor etc.).
I've put these "types" in a separate table with codes (systemtype_code in the example below).
What I want to achieve (it's already working but not flexible) is :
- I would like custom "values/attributes" for each system type.
For example, if the system type is "SSR", I would like to have fields such as "rack", "rack location", etc. If the system type is "RTR", I would like to have fields such as "number of ports", "syslog server (listbox containing other items)", etc..
You get it I think.
I manage to do it with something similar to the example below (some fields can be used for many system types naturally), but it's very simple. It works perfectly, but it's limited as the field can just be of one type (TEXT, VARCHAR or other stuff like that).
So my questions are :
- Is my method the good one ? (it's going to do huge link tables at the end)
- How can I improve it so that it allows some custom fields to be of different types (e.g a listbox etc. for example)
Thanks
Here is an example of what I currently have :
--------------------
table : systems
--------------------
sid
name
description
building_code
responsible_user
systemtype_code
--------------------
table : systemtypes
--------------------
systemtype_code
systemtype_name
--------------------
table : systemattrs
--------------------
systemattr_id
systemattr_name
--------------------
table : systemattrvalues
--------------------
sid
systemattr_id
systemattr_name
--------------------
table : l_systemattrs_systemtypes
--------------------
systemattr_id
systemtype_code
To get the attributes related to a system, I can simply make a query like :
SELECT a.systemattr_name,
v.systemattr_value
FROM systemattrs a,
systemattrvalues v,
systemtypes t,
l_systemattrs_systemtypes l
WHERE v.sid = 'MY_DESIRED_SYSTEM_ID'
AND l.systemattr_id = a.systemattr_id
AND l.systemtype_code = t.systemtype_code
AND v.systemattr_id = a.systemattr_id
It works nicely, but is not exactly what I want.
Let me know if you want a database design schema to understand my question a little better.