473,542 Members | 2,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lots of Bits

Hi there, I'm not sure if this the appropriate group so apologies if
it lies outside the boundary.

Senario: I have a customer table with contains a bunch of different
bit values that represent true/false values pertaining to the
customer. I decided for the purpose of clarity I would move these
values into another table. This way I would keep the customer details
(name, age, etc) separate from these values.

Question: Is this a good idea? Or chould i somehow tally up all these
bit values and store it in one field in the customer table?

The application is a website and it is built using ASP.NET (VB.NET)

Cheers,
Jack
Nov 19 '05 #1
6 1210
Without knowing more about the tables in your database and how they are
related and which "real-world" entities are represented by your tables....
I'd think that you are creating more work for yourself by splitting out a
table simply to hold 1:1 data (you now may have to join the tables in order
to get the bits for a given customer). You do not explain how separating the
bits out into another table increases clarity. I just don't see it (granted,
I have very little to go on).
Regarding tallying up all the bit values - no way - don't do it; that's
creating a lot more work, violates the First Normal Form (of relational
design; "no multi-part values"), and will definitely create a lot more work
for you (e.g., what happens when you need to change one of the bit values?).
Plus, what would the tally actually mean? Answer: it would mean nothing: SUM
1 + 0 + 1 + 1 = 3. Also, SUM 0 + 1 + 1 +1 = 3. So the value of 3 is
meaningless (tells you absolutely nothing beyond the fact that 3 of 4 bits
had a value of 1; unless that is the only fact you are interested in, the
value is meaningless).

You really need to tell us a lot more about the meaning and use of your
data. Plus, the SQL Server/Programming group frequently gives feedback on
this sort of issue (it really has nothing to do with ASP.NET).

Good Luck!

"Jack" <ja****@humlog. com> wrote in message
news:6e******** *************** **@posting.goog le.com...
Hi there, I'm not sure if this the appropriate group so apologies if
it lies outside the boundary.

Senario: I have a customer table with contains a bunch of different
bit values that represent true/false values pertaining to the
customer. I decided for the purpose of clarity I would move these
values into another table. This way I would keep the customer details
(name, age, etc) separate from these values.

Question: Is this a good idea? Or chould i somehow tally up all these
bit values and store it in one field in the customer table?

The application is a website and it is built using ASP.NET (VB.NET)

Cheers,
Jack

Nov 19 '05 #2

Yes sorry I was a bit vague.

These values are used for filtering purposes e.g. searching for
customers who best matches criteria set out in a marketing campaign i.e.
match customer filter values with campaign filter values.

Hope that make sense.

When I say 'clarity' I just mean the customer table was becoming massive
so I thought I'd move the filter values into a another table (yes it
requires another join - i may change it back)
I definitely used the wrong word in 'tally' - sorry. I mean representing
all bit values as one binary value. This value can then be stored in the
database (as a decimal or hex). If one value is just say changed then a
new binary is formed and hence a new value in the database.

Does this make any sense?

This is just a 'throw out there' question as i would be interested in
opinions.

Cheers,
Jack

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3
ja****@humlog.c om (Jack) confessed in
news:6e******** *************** **@posting.goog le.com:
Hi there, I'm not sure if this the appropriate group so apologies if
it lies outside the boundary.

Senario: I have a customer table with contains a bunch of different
bit values that represent true/false values pertaining to the
customer. I decided for the purpose of clarity I would move these
values into another table. This way I would keep the customer details
(name, age, etc) separate from these values.

Question: Is this a good idea? Or chould i somehow tally up all these
bit values and store it in one field in the customer table?

The application is a website and it is built using ASP.NET (VB.NET)

Cheers,
Jack


What purpose would it serve?

One usually creates a new table to normalize a database, that is, to prevent
duplication of data. It's a time against space tradeoff, because you have
added a level of indirection to your data and must now use a map to manage
the pointers, and write the code (via joins) that use that map to get at the
data.

Perhaps if users had common profiles (bit settings) you might try it, but
this sound like more trouble than it is worth. Basically, this is one number
per user, right?

-- ipgrunt
Nov 19 '05 #4
Okay, your "tally" makes more sense. IMHO, you're getting into some
interesting trade-offs with this "binary value" stored in the db and it
comes down to what you are comfortable living with (like many design
considerations) . If the number of binary columns is large and you are
searching on them, then you should also index them. This has some
maintenance and performance and complexity implications. Compared with one
integer column that holds some unique value, then the query is simplified
and performance is perhaps increased for the database. Of course a database
purist might frown upon it for more theoretical purposes as well as the many
practical purposes related to maintaining the unique int value that has your
application-specific meaning. I suspect that if you posted this in the
microsoft.publi c.sqlserver.pro gramming group that you'd get some intersting
perspective and rationalle beyond what I pointed out (which you probably
were aware of before I pointed it out). As for my opinion; I'd most
definitely lean toward keeping the bits in their own columns... it just
gives you so much more flexibility in extracting information. You can always
create and programmaticall y maintain a separate denormalized table that
could have your special "tally" column and then query that table for your
current searching/reporting purposes. This gives you the best of both worlds
and is possibly the easiest solution to modify in the future because you
always have the original bits to go back to while your queries can be
simpler and perform fewer (perhaps zero) joins and therefore run faster
because they are hitting a single denormalized table. You get the idea.

Good Luck!

"Jack Burton" <ja****@humlog. com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..

Yes sorry I was a bit vague.

These values are used for filtering purposes e.g. searching for
customers who best matches criteria set out in a marketing campaign i.e.
match customer filter values with campaign filter values.

Hope that make sense.

When I say 'clarity' I just mean the customer table was becoming massive
so I thought I'd move the filter values into a another table (yes it
requires another join - i may change it back)
I definitely used the wrong word in 'tally' - sorry. I mean representing
all bit values as one binary value. This value can then be stored in the
database (as a decimal or hex). If one value is just say changed then a
new binary is formed and hence a new value in the database.

Does this make any sense?

This is just a 'throw out there' question as i would be interested in
opinions.

Cheers,
Jack

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #5
It's all about tradeoffs.

Scenario #1 (current): use a bit-encoded field to store boolean(?)
attributes
Scenario #2 (proposed): store these attributes in a joined table, one row
per "true" attribute.
Scenario #3: break the attributes into discrete bit columns. One column
per attribute.

Pros+/Cons- of #1:
+ No joins
- Have to do ANDs and XORs to find matches. Does your db support these
constructs?
- Have to do two queries to apply a single filter; one to specifically
match on "true" attributes, the second to specifically match on "false"
attributes. You have to intersect the results of these two queries to get
your final list. If you only care about "true" matches this doesn't apply.
- Less efficient to manage
- More difficult to understand
+ Might be faster. Maybe.
- Limited number of attributes, depending on the bitfield size.
+/- Moderately expandable; but requires some code to interpret the meaning
of the bit fields. Eliminating a bit field requires an update to the entire
table and your code as well...

Pros+/Cons- of #2:
- Requires a join per attribute test. If you're testing for the
existance/non-existance of three attributes, you need three joins to your
attribute table.
+ Much easier to understand
+ More efficient to manage
- Might be slower. Maybe.
+ Unlimited number of attributes.
+ Ability to link other special data to specific attribute types if you
like; e.g. if you were doing real-estate, you could say "yes" it has
parking, and then link to parking details stored elsewhere.
+ Hugely expandable. Add attributes. Delete attributes. Easy as pie.

Pros+/Cons- of #3:
+ Much easier to understand
+ More efficient to manage
+ No joins
+ Fastest of the 3. No binary math, no joins.
+ Expandable, but limited by the number of fields your table can have.
Adding/Deleting attributes requires a table structure change, but no data
migration.
I'd choose between #2 and #3 personally, depending on the amount of
expansion I need. If I have just a handful of attributes and they change
rarely I'd go with #3. If attributes are a fairly liquid concept, I'd go
with #2.

/// M
"IPGrunt" <me@privacy.net > wrote in message
news:Xn******** *************** ******@130.133. 1.4...
ja****@humlog.c om (Jack) confessed in
news:6e******** *************** **@posting.goog le.com:
Hi there, I'm not sure if this the appropriate group so apologies if
it lies outside the boundary.

Senario: I have a customer table with contains a bunch of different
bit values that represent true/false values pertaining to the
customer. I decided for the purpose of clarity I would move these
values into another table. This way I would keep the customer details
(name, age, etc) separate from these values.

Question: Is this a good idea? Or chould i somehow tally up all these
bit values and store it in one field in the customer table?

The application is a website and it is built using ASP.NET (VB.NET)

Cheers,
Jack
What purpose would it serve?

One usually creates a new table to normalize a database, that is, to

prevent duplication of data. It's a time against space tradeoff, because you have
added a level of indirection to your data and must now use a map to manage
the pointers, and write the code (via joins) that use that map to get at the data.

Perhaps if users had common profiles (bit settings) you might try it, but
this sound like more trouble than it is worth. Basically, this is one number per user, right?

-- ipgrunt

Nov 19 '05 #6

Thank you for all your replies. It have given me a much clearer idea on
handling this type of senario.

Cheers,
Jack

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1504
by: Christopher Benson-Manica | last post by:
I have a situation where I have many (more than 32) boolean flags: var foo=true; var bar=false; var baz=false; // etc. At various points in the script, these flags may be set or unset. There is a point where an action is to be taken only if all the flags are false. I also need to debug this check of all flags - i.e., print
40
5660
by: aku | last post by:
I'm looking for the absolute fastest way to count the nr of bits that are set to "1" in a string. Presumably I then first need the fastest way to do this in a byte. I think this is it, but welcome any improvements: i = 0; if (g && 1) i++; if (g && 2) i++;
7
4790
by: sathyashrayan | last post by:
Group, Following function will check weather a bit is set in the given variouble x. int bit_count(long x) { int n = 0; /* ** The loop will execute once for each bit of x set,
6
3870
by: barcaroller | last post by:
I couldn't find a message-digest newsgroup, so I posted here. I have a C function that converts a string of arbitrary length to a 32-bit hash value. I realize this is overkill but I used OpenSSL's sha1() to convert the string to a SHA-1 160-bit message digest. The question is: how do I use these 160 bits to get my final 32 bits? Should I...
15
4770
by: steve yee | last post by:
i want to detect if the compile is 32 bits or 64 bits in the source code itself. so different code are compiled respectively. how to do this?
11
14640
by: Mack | last post by:
Hi all, I want to write a program to count number of bits set in a number. The condition is we should not loop through each bit to find whether its set or not. Thanks in advance, -Mukesh
77
4207
by: borophyll | last post by:
As I read it, C99 states that a byte is an: "addressable unit of data storage large enough to hold any member of the basic character set of the execution environment" (3.6) and that a byte must be at least 8 bits: "The values given below shall be replaced by constant expressions suitable for use in #if
11
1844
by: JoeC | last post by:
I am working on a graphics program but my question has nothing to do with graphics but trying to get an algorithm to work. I set graphics from a 16x16 grid to bits of a graphic with: bitData = binTemp * 128 + binTemp * 64 + binTemp * 32 + binTemp * 16 + binTemp * 8 + binTemp * 4 + binTemp * 2 + binTemp; But I want to populate...
11
2329
by: spasmous | last post by:
Just wondering.
0
7397
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7582
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7675
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5877
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5257
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1809
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
948
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
626
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.