1

I have a Settings table:

CREATE TABLE `Settings` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` varchar(100) NOT NULL,
  `Name` varchar(250) NOT NULL,
  `Description` text NOT NULL,
  `Default` varchar(30) NOT NULL, <<<<<<<
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

The Default value may however be integers, booleans, text, enums etc. etc. I have set it to varchar right now, and when retrieving the setting, I will know what setting it is, e.g Send me daily emails - True/False, and do a case at the application level given that I know the type the value should be for that particular setting.

Is there a better way of doing this?

2
  • In contrast to my answer to your other question, where I suggested a model that looks like EAV, in this case... danger, your long-term interests may not be served by this approach. Columns of the appropriate types are likely better. Commented Jan 13, 2014 at 12:51
  • @Michael-sqlbot is this what you mean programmers.stackexchange.com/a/163607/59685
    – Lee
    Commented Jan 13, 2014 at 15:37

1 Answer 1

1

The approach you are proposing is workable but informal. A more formal approach can be found in my answer to this question.

The basic pattern is called a Property Bag.

2
  • Very interesting, are there any books written on this sort of thing (patterns such as Property Bags and so on)
    – Lee
    Commented Jan 13, 2014 at 13:04
  • @lee - There are lots of good books - too many to be on topic for StackExchange. Try Googling around for technical books that include the word "Cookbook" in the title. That's a good indication that it's a collection of patterns/applications/best practices.
    – Joel Brown
    Commented Jan 13, 2014 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.