I need to design a DB for storing key-value data. List of Key names isn't fixed and should expand at later point. I don't want to create a table with a column for each key, because I'll need to add columns frequently and it might grow too big, and I understood that the Entity-Attribute-Value design isn't efficient. I thought of the following type of table design, and I'm asking if it makes any sense and does anyone can come up with any drawbacks related to efficiency, table size or any other issue -
Each column in the table is of a different data type; irrelevant columns for a key are NULL:
ID |DataType |KeyName |ValInt |ValSmallInt|ValBool |ValStr |ValText |ValDate
-------------------------------------------------------------------------------
1 |1 (int) |Width |100 |NULL |NULL | NULL | NULL | NULL
2 |1 (int) |Height |200 |NULL |NULL | NULL | NULL | NULL
3 |2 (bool) |IsActive|NULL |NULL |false | NULL | NULL | NULL
4 |3 (text) |URL |NULL |NULL |NULL | NULL | w.com | NULL
5 |1 (int) |Size |4 |NULL |NULL | NULL | NULL | NULL
6 |4 (date) |Created |NULL |NULL |NULL | NULL | NULL | 2/2/2012
Number of columns will be as the number of all datatypes (about 30?).
The DataType column is a flag of type int which is used for the caller - it tells him what column to take the value from.
Each row is actually a property of some object in other table. A set of rows makes a set of properties for that object and usually a SELECT will get the whole set.