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?

  • 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. – Michael - sqlbot Jan 13 '14 at 12:51
  • @Michael-sqlbot is this what you mean programmers.stackexchange.com/a/163607/59685 – Lee Jan 13 '14 at 15:37
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.

  • Very interesting, are there any books written on this sort of thing (patterns such as Property Bags and so on) – Lee Jan 13 '14 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 Jan 13 '14 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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