I need to design a Key/value table in my database and I\'m looking for guidance on the best way to do this. Basically, I need to be able to associate values to a dynamic se
It seems to me like you might have a couple design choices.
Choice 1: A two table design you hinted at in your answer
Keys (
id int not null auto_increment
key string/int
)
values (
id int not null auto_increment
key_id int
value string/varchar/int
)
Choice 2: perhaps as sambo99 pointed out you could modify this:
keys (
id int not null auto_increment
key string/int
hash_code int -- this would be computed by the inserting code, so that lookups would effectively have the id, and you can look them up directly
)
values (
id int not null auto_increment -- this column might be nice since your hash_codes might colide, and this will make deletes/updates easier
key_id int -- this column becomes optional
hash_code int
value string/varchar/int...
)
--