|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Friday, May 18, 2007 3:36 PM
Points: 10,040,
Visits: 1
|
|
| Comments posted to this topic are about the Question of the Day for 20 Apr 2007 posted at http://www.sqlservercentral.com/testcenter/qod.asp?QuestionID=1011.
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Wednesday, January 05, 2011 9:32 AM
Points: 694,
Visits: 89
|
|
The explanation says "This returns a 5...", when in fact the rest of the explanation correctly states that it returns 7.
Rick townsends.ca
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:38 AM
Points: 5,300,
Visits: 7,244
|
|
The question is okay (though I'd personally prefer to ignore the bitwise operators - too much people with a string backgroun in procedurall programming and a weak level of DBMS skill will want to use them). But I really don't understand why this question is in the category "Design and Theory". Clearly, it should be in the "T-SQL" category, right?
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, November 01, 2012 1:18 PM
Points: 110,
Visits: 261
|
|
I'm trying to visualize a life of bitmasks without bitwise operators. I just had to disable bit 1 on a bunch of rows, and then later reenable bit 1. How would you propose doing this without bitwise operators? With them, it was a snap.
If you would suggest changing the schema, that doesn't work for me. I'm dealing with an off the shelf forum application that would be a ton of work to change the database schema for.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:38 AM
Points: 5,300,
Visits: 7,244
|
|
Hi Adrian, Try to visualize a life without bitmasks instead..... Remember the rules for first normal form - every column should only hold atomic values. Clearly, a bit mask violates that rule. If you want to store 8 yes/no values, use 8 columns instead. Define them as bit, if you must (I am not as opposed to the bit datatype as some, but not a big supporter either), and SQL Server will still use only 1 byte to store them. Or store them as CHAR(1) with a CHECK constraint to limit the population to 'Y' of 'N', and gain a lot of clarity at the price a mere 7 extra bytes.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, June 17, 2007 9:43 AM
Points: 5,
Visits: 1
|
|
What are some instances where a bitmask would be useful? I've been programming for a while now and never really understood their purpose. Thanks! Bonnie
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:38 AM
Points: 5,300,
Visits: 7,244
|
|
Hi Bonnie, Usage of bitmasks was very common and useful up until the seventies, when memory footprint off applications and data came at a premium. If you have to run a program on your home computer with only 32 KB (yes, KILObytes) of memory -half of which was reserved for video memory, keyboard memory, and firmware-, you get to appreciate the value of combining multiple values in a single bytes. And when data has to be stored on a casette recorder with a recording andd playback speed of 300 bits per second, you get to apppreciate the savings even more. Same for professional development. Those computers often had a whopping 64 kB to their disposal - still good reason to save a few bytes. Storage was on floppy disks, or, for the lucky, on hard disks. One of the earliest hard disk bragged a storage capacity of 5 MB, and came at a price of $ 50,000. Try telling your boss: "The good news is, I decomposed the bit mask in the main file for orders into seperate fields; the bad news is, we need to add a second 5 MB hard disk..." In modern computer development, bit masks are still used quite often in low-level languages like assembly language, or C. These languages are commonly used for the most performance-critical bits of applications, and since many processors have instructions in their instruction sets for handling bit masks, using bit masks can yield a performance boost. But in modern third-and-higher generation languages, bit masks have no place at all. And in databases, they should be outright forbidden. 
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, November 01, 2012 1:18 PM
Points: 110,
Visits: 261
|
|
Hugo, It sounds like you have the luxury of getting to define your own database schema. In the small company that I work for, the database guy (yours truly) has to support integration of any other software we need that uses the DB so bitmasks are a fact of life.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:38 AM
Points: 5,300,
Visits: 7,244
|
|
Hi Adrian, Sometimes I do, sometimes I don't have that luxury. I am well aware of how much some third-party DBs suck, and how awful it can be to be stuck with them. That makes knowledge of what bitmasks are and how they can be operated a Good Thing for those in a similar position as you currently are - but it still doesn't make it right to advertise the use of bitmasks as if they are a Good Thing in themselves. (Note - I don't think that the QOTD actually "advertises" the use of bitmasks, but it does teach people about them without the "don't do this unless forced to by crappy third-party software" disclaimer that I think ought to be attached here).
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, June 17, 2007 9:43 AM
Points: 5,
Visits: 1
|
|
Hugo, Thanks for the quick response and the practical advice! I thought I may have been missing out on a good shortcut, but I will stay away from them. Bonnie
|
|
|
|