How do I store metadata to describe assets?
Considering that I don’t know in advance which metadatafields I’ll have.
I have a table with assets (let’s say persons),
a table with metadata fields (“name”, “age”, “day of birth”, …)
a table with metadata values that links to the metadata fields table (“John Doe”, 44, “1968-10-10”, …)
and a crosstable metadata that links the metadatafields to the assets.
My problem is how do I handle the different datatypes in the metadata fields table.
“John Doe” is text, 44 is int, 1968-10-10 is a date.
Do i store these in a txt-field in my metadatafields table, but will I be able to compare dates?
Or do I store the datatype in this table and do I make 3 fields for txt,int and date. But then I have a lot of empty fields.
Or do I make different metadata fields tables for each datatype (eg: metadatafields_txt, metadatafields_int, metadatafields_date) but then I can’t link properly to the metadata table.
What is the best practice here?
tx
All of these are valid options (with a slight modification in the first case – I would store an additional field to indicate which type of data is being stored, and convert appropriately where required).
The third option should be viable – instead of inner joining to one table, you would left join to the three different tables in your query.
As Eugen says, it depends – do you know in advance roughly how many metadata records (just to an order of magnitude – thousands, millions, more?) you expect to have, and whether they are likely to be overwhelmingly of one type?