views:

46

answers:

2

There are few string lists in my web application that i don't know where to store in DB or just class.

ie. I have 7 major browsers with which users enter the site. I want to save these stats thus i need to create browser column in UserLogin database. I don't want to waste space and resources so i can save full browser name in each login row. So i either need to save browserID field and hook it up with Browsers table which will store names following db normalization rules or to have sort of Dataholder abstract class which has a list of browsers from which i can retrieve browser name by it's ID...

The question what should i do ? These few data lists i have contain no more than 200 items each so i think it makes sense to have them as abstract class but again i don't know whether MS-SQL will handle multiple joins so well. Think of idea when i have user with country,ip,language,browser and few more stats ..

thanks

+1  A: 

Hey,

MS SQL handles multiple joins really well; it's up to you where you want to store the data. You can also consider XML too, as another option. I would consider the database or XL; it is easier to change the values than if the values are in code (have to recompile/deploy to change when in production).

HTH.

Brian
another reason why i want abstract classes is because for instance user enter the site then i need to store his login so i need to get IDs of all those small lists before i insert login info which will require many small sql queries or to combine all of them into one huge stored procedure.i dislike idea of that... this is main reason why i want to switch to Lists inside of code.
eugeneK
+1  A: 

I have been on both sides of the fence about this.

My rule of thumb is:

If one of these lists changes, will I have to do changes to the code, too?

(e.g..: in your case, if someone writes "yet another browser" tomorrow, will I need to write code that caters for it?)

If the answer is "most probably yes" or "definitely" you can leave it inside code. In all other cases (even just a "maybe, 50%-50%) you better put it in the DB, or at the very least a property file.

And please consider this, too: if you expect to have to provide statistics based on this data (e.g.: "how many users use Explorer") you better put it in the DB anyway: it becomes part of your domain data and therefore it must be there.


About the "domain data" part.

The information stored in your DB is the "domain data" of your application. It is, in a sense, a (hopefully consistent) representation of what your application is about - it represents the "known universe" for your application. If you agree to this definition, then you must also accept that it does not make sense to have 99.9% of your "reality" in the DB, and 0.1% outside of it - if nothing else, it makes some operations cumbersome (if you only store the smallint you can't create meaningful reports without either post-processing them using the class to decode "1" into "Firefox" or providing some other key for the end-user). It also makes impossible for you to leverage some inherent DB techniques like foreign key (if you just use a smallint without correlating it to any other table, who guarantees that "10" is an acceptable value in your domain?)

p.marino
I do not understand what do you mean by "domain data" ? Of course i will use different statistics but again only tinyint will be stored in DB while real name will be inside of class...thanks for advice about the rest. data like browsers, countries, languages doesn't change that often. so yet another reason to keep it in class...
eugeneK
Edited answer trying to clarify a bit better.
p.marino