views:

86

answers:

5

Hi there,

i have a table and one of the columns is co_com

this is communication preferences

there are three options (and only ever will be) i dont want to have a seperate column for these values

so i was thinking of storing them as

sms/email/fax sms = yes email = no fax = yes which would be stored as: 101

but, im thinking thats not the best way

what other ways can you see?

yes i am aware that this is a subjective question

but im not sure how else to ask.

+3  A: 

Storing combinations of logical values as coded binary is... 1900's. Seriously, how much does disk space cost these days, and how much do you save by cramming three bits of information into a single number rather than three bytes or characters?

Go on, create three columns with sensible names, and store either 0's and 1's in them, or if your DB is weird that way, story 'Y' and 'N'. But don't do this binary cleverness stuff. It will bite you eventually when you try to write sensible queries.

Carl Smotricz
Of course, if you just used BIT-typed columns, everything would be fine...
Dave Markle
Not everybody has a database that's heard of bit types. As far as I know, it's still standard practice in Oracle databases to code booleans as single characters. (blech!) Don't ask how this product came to be the market leader!
Carl Smotricz
Oracle's handling of string nulls alone is enough to make me want to vomit.
Dave Markle
+6  A: 

You're correct. That is in fact not the best way.

You say you don't want to have separate columns for these values, but that's exactly what you should be doing.

Dave Markle
it's more the hassel of getting them setup that i was trying to avoid, but by the sounds of it, it'll bite me later if i dont..stupid 7 working day's to answer your query support staff..
Hailwood
@Hail: We've all been down that road before. We're just your inner voice of conscience... :)
Dave Markle
A: 

In my mind, columns is the best way to go, for ease of use if nothing else. The columns are straight forward and won't be confusing in the future. BUT I wouldn't say storing them in a single column as 3 digits is necessarily bad, just confusing. Save yourself the headaches later and do 3 columns.

ThrivingKings
If it's confusing, then it *is* necessarily bad.
Dave Markle
It's not just confusing, it's bad. It was done when space was at a premium, because the cost of space overruled the cost of confusion/ease-of-use.
George Marian
On a side note, situations like this are the reason that we need to understand what came before us, even if that information seems useless. This is also the reason that we must strive to learn as much as we possibly can about the tools/techniques/technology we use.
George Marian
A: 

Another point of view would be to have another table called com_options for example. Have an ID field and an options field, store all of the different communication options combinations in the options field along with a unique ID in the ID field and in your co_com table have an opt_id field referencing the ID in the com_options table. Then use an INNER JOIN to join these 2 tables together.

Chief17
Are you an Oracle consultant? Do you get a provision on hardware sales? ;)
Carl Smotricz
Lol, naa, just adding another point of view, might be more processor intensive but its the most normalized way that i can think of at the moment :oP... However, if you wish to buy any such goods in the near future, feel free to cantact me :oP jk
Chief17
A: 

If your DB is MySQL, then you can use SET datatype.

It's OK, don't worry -- sometimes we should denormalize tables :)

But if your DB isn't MySQL, then you also can use this method, but implementation will be non-your-DB-native. Also bitwise logic on a big bunch of data works very well vs default normalize d one-to-many relation. Because it`s more computer-oriented.

Alexander