Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I structure my settings table with MySQL? [closed]

Tags:

What's the best way to structure a MySQL table for storing admin settings?

Like this?

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

Or like this?

|--------|_setting1_|_setting2_|_setting3_|_setting4_|_setting5_| Settings |    a     |    b     |    c     |    d     |    e     | 

Or maybe some other way?

like image 629
Cam Avatar asked Mar 18 '10 11:03

Cam


People also ask

How do you organize a table in MySQL?

There is no way to organize tables hierarchically that is meaningful to MySQL. As others have noted, you can maintain separate schemas (in MySQL, databases), or you can develop and use a table naming structure that organizes your tables in a way that is meaningful to users (but is still not meaningful to MySQL).

How do you close a table in MySQL?

To remove a table in MySQL, use the DROP TABLE statement. The basic syntax of the command is as follows: DROP [TEMPORARY] TABLE [IF EXISTS] table_name [, table_name] [RESTRICT | CASCADE];

What is correct syntax for table in MySQL?

Use a CREATE TABLE statement to specify the layout of your table: mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DATE, death DATE); VARCHAR is a good choice for the name , owner , and species columns because the column values vary in length.

Which MySQL command is used to modify the structure of table?

MySQL (and MariaDB) allows you to change the structure of tables with the ALTER TABLE SQL command.


1 Answers

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.

Edit

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

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

:-)

like image 103
Ben Everard Avatar answered Oct 17 '22 10:10

Ben Everard