我应该如何结构我的设置表与mysql? [英] How should I structure my settings table with mysql?

查看:123
本文介绍了我应该如何结构我的设置表与mysql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MySQL存储一堆管理设置 - 什么是最好的结构表格的方法?

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

像这样?

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

还是这样?

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

还是其他方法?

推荐答案

表名='settings'

Table name = 'settings'

name  | varchar <-- primary key
value | varchar

然后你可以这样查询:

SELECT * FROM settings WHERE name = 'default_printer';

此选项很好用,容易使用,可以与10或10,000个设置配合使用。使用另一个选项,您必须添加一个新列,这将是一个完全没有意义的时间浪费。

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');

: - )

这篇关于我应该如何结构我的设置表与mysql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆