Hello all together,
i ran into a problem about database design i don't know to solve on my own anymore, as of this i'd like to consult you
Background information:
I have a list of entities* wich may have an increasing (so up to unlimited) amount of properties.
* The list of entities may change as of addition and deletion of entities..
The properties have diffrent datatypes (basicly text or numbers) and in somecases there are additional information such as notes concerning the value or an date of the value. (~ "Multifield Properties" -.- )
In some cases there is no property value available for a specific entity.
Query requirements:
Get a result of selected/all entities with selected/all properties. (the query itself might be generated by some script that knows the list of entities and all available properties).
So ideally a result structure would be:
Code:
+--------+-----------+-----------+-----+-----------+
| entity | property1 | property2 | ... | propertyn |
+--------+-----------+-----------+-----+-----------+
| ...... | ......... | ......... | ... | ......... |
| ...... | ......... | ......... | ... | ......... |
My attempts/thougts so far:
1)
I could put everything into one table, however due to the many properties i may run out of fields, and with the mentioned extra information it will get quite messy.
+ easy to query
+ no datatype issues
- limitation in fields
2)
The second possibility would be to have an extra table for each property or group of properties, that would be kinda comfortable to query with simple joins, but gets messy on the tables side, and is basicly the first structure splitted into multiple tables :/
+ no datatype issues
= meets the "all entities with selected properties" requirement with almost plain sql
- lots of tables
3)
What i ended up for now, is a three table structure:
tbl_entities
fields: eid, name
tbl_properties
fields: pid, property, datatype
tbl_values
fields: vid, pid, eid, dbl_value, txt_value, note_of_value, date_of_value
However, however at this point of have absolutly no idia for an query to achieve something that comes close to the desired result.
So what i am after, is an DB design that meets requirement, but stores the data as effezient and normalized as possible :/
Thanks =D