Cam Cam - 1 year ago 79
MySQL Question

How should I structure my settings table with mysql?

I want to use MySQL to store a bunch of admin settings - what's the best way to structure the table?

Like this?

Setting _|_ Value
setting1 | a
setting2 | b
setting3 | c
setting4 | d
setting5 | e

Or like this?

Settings | a | b | c | d | e |

Or maybe some other way?

Answer Source

Table name = 'settings'

name  | varchar <-- primary key
value | varchar

Then you can query like this:

SELECT * FROM settings WHERE name = 'default_printer';

This option is nice and easy and it will work well with 10, or 10,000 settings. With the other option you'll have to add a new column, which would be a completely pointless waste of time.


After your 1st comment you could choose multiple values like this:

SELECT * FROM settings WHERE name IN ('default_printer','default_page_size');


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download