If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > no entry vs '0'

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-08-09, 03:03
kevinb kevinb is offline
Registered User
 
Join Date: Jun 2009
Location: Hawaii
Posts: 3
no entry vs '0'

I have a database design issue I'm trying to work out and I thought I'd come to the experts.

I have a table "counts" which does just that - holds counts of certain objects/datasets. The majority of the table is foreign keys describing the components of each sum in the table - type, source, location, etc.

My scenario is, say I have 5 possible types of widgets being counted. If one source only contains 1 widget, do I enter '0' for the others or not even make an entry into the DB and work it out via code when doing statistics/charts?

Is there a standard for "positive feedback" for the lack of a better term? Meaning, with 0's there's less ambiguity vs no entry could mean there's a problem.
Reply With Quote
  #2 (permalink)  
Old 06-08-09, 05:09
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
I can’t think of a good reason for treating a count of zero as different from any other number.

It is worth noting that SQL has an odd feature/quirk/bug (depending on your point of view) that’s relevant to your question. Given the following query:

SELECT SUM(Quantity) Quantity FROM tbl WHERE Product = 'Widget';

SQL will return a NULL Quantity if there are no Widgets in the table, instead of the mathematically obvious and common-sense answer of zero. (Null is the result decreed by the SQL standard anyway. Check your particular DBMS to see if it actually does this.)

By recording a zero instead of just not having a row you can ensure that such queries are less likely to return a null when you don’t expect one.
Reply With Quote
  #3 (permalink)  
Old 06-08-09, 05:35
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
mind you it does beg the question why you have a table which contians 'counts' of items already in the db.....
or have I misread you design?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #4 (permalink)  
Old 06-08-09, 23:39
kevinb kevinb is offline
Registered User
 
Join Date: Jun 2009
Location: Hawaii
Posts: 3
Quote:
Originally Posted by dportas
I can’t think of a good reason for treating a count of zero as different from any other number.
So simple, yet so profound in my case.

I adjusted the perl code feeding the database and everything else just snapped into place.

Thanks
Reply With Quote
  #5 (permalink)  
Old 06-08-09, 23:42
kevinb kevinb is offline
Registered User
 
Join Date: Jun 2009
Location: Hawaii
Posts: 3
Quote:
Originally Posted by healdem
mind you it does beg the question why you have a table which contians 'counts' of items already in the db.....
or have I misread you design?
I might have not stated it correctly. The table isn't a count of things in the db, else I'd hopefully be able to use the COUNT function. The counts are fed from different sources via perl to the database. I'm basically writing something to monitor and track I/O for different systems.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On