tags:

views:

30

answers:

2

I have a table with some fixed columns id,title,created.., but there I need put some optional data from the user that I cant define a specif column, but I need this data for search from others users. What the best way?

  1. Store a serialized array
  2. Leave some column optionals ( exemple:leaves any 10 column opt1,opt2,opt3...)
  3. Create a new table (dataid,uid,key,value) and new rows for each data.

the data would be like key:value pair

What should the best way to record any undefined optionals data from the user and optimize to search?

Good Day

+2  A: 

Definitively 3). Storing a serialized array means being dependend on a language (php, json etc), and selecting via sql is impossible. 2) ist bad, because of several reasons; mainly, you are less flexible in extending and selecting. Create a meta table like 3), this is an established approach.

Update: 3) must be improved a bit: Create a table like this:

UID | key | value

not:

UID | key_value

schneck
A: 

The 3rd approach is the best because you can search easily inside the db and you will not worry about how many values per user

RioTera