The Database Design Resource Center
The Database Design Resource Center
 
 FAQ   Search    Memberlist   Usergroups    Register    Profile   Log in to check your private messages   Log in   The Website
Dates and NULLs

 
Post new topic   Reply to topic    Database Design Resource Forum: Forum Index -> The newbies section: Basics on DB design
 Display posts from previous 
Display posts from previous:   

 Dates and NULLs 
Author Message
sak
User


Joined: 20 Jan 2010
Posts: 3

PostPosted: Wed Jan 20, 2010 2:13 pm    Post subject: Dates and NULLs Reply with quote

I have read many of the articles/forum topics on this site and on Database Debunkings about NULL values and the issues involved.

One question I have is dealing with dates and NULLs when the date is not known yet. In an Employees table one of the fields in TerminationDate. This field has a value of NULL if the employee is active. Is this use of NULL an issue? Are there recommend solutions to avoid the NULL? I have thought of using a Default value but am not sure what a good value would be.

Thank you
View user's profile Send private message

  
Author Message
alf-admin
User


Joined: 07 Nov 2007
Posts: 229
Location: Norway

PostPosted: Thu Jan 21, 2010 11:59 am    Post subject: Reply with quote

Yes, you bring up an interesting issue. In your case (IMHO) you (or rather, the construction you describe) are mixing two different entities: EMPLOYEE and ENGAGEMENT (or whatever you want to call it). Let me elaborate:

I often see EMPLOYEE entities with a start and end date for engagement. And of course, when the employee is active, end date is NULL. But imagine where you have an employee coming and going? In the case described above, an employee can only be employed once... There should really be another entity that recorded, for a given employee, when he started, and when he ended being an employee, possibly classified by a type entity marking each row as a "Begin" or "End" event for the engagement.

The problem of having a NULL for end date as you describe it, is not a NULL problem: It is a flaw in DB design, not recognizing that there is a one-to-many relationship between an employee and his/her ENGAGEMENT as an EMPLOYEE.. The flaw is more often a result of deliberately over-simplifying the DB design, also known as lazyness Wink

Just as a short remark on your question.

Edit:

Actually, your example is a perfect complementary to one of my main "theses": If your DB design contains attributes that allow NULLs, it is a very good indication of incomplete/flawed DB design.
_________________
All the best,
Alf
Forum Admin
Light travels faster than sound: That's why so many people appear bright until you hear them speak...
www.databasedesign-resource.com
The Database Normalization eBook
View user's profile Send private message Visit poster's website

  
Author Message
sak
User


Joined: 20 Jan 2010
Posts: 3

PostPosted: Thu Jan 21, 2010 3:21 pm    Post subject: Reply with quote

Thank for your quick response.

alf-admin wrote:
There should really be another entity that recorded, for a given employee, when he started, and when he ended being an employee, possibly classified by a type entity marking each row as a "Begin" or "End" event for the engagement.
I just had a lightbulb moment and understand how this should work now. This would also provide a solution for tracking other 'Engagement' types of events, ie, Maternity Leave.

Quote:
The flaw is more often a result of deliberately over-simplifying the DB design, also known as lazyness Wink
When I started this job the database had already been developed by someone obviously ignorant of any design knowledge. Besides not even being 1NF there were no relationships between the tables. Shocked
View user's profile Send private message

  
Author Message
alf-admin
User


Joined: 07 Nov 2007
Posts: 229
Location: Norway

PostPosted: Thu Jan 21, 2010 3:30 pm    Post subject: Reply with quote

sak wrote:
just had a lightbulb moment and understand how this should work now.


Happy for that. And yes, give it a little thought and the pieces fall in place, not?

Quote:
This would also provide a solution for tracking other 'Engagement' types of events, ie, Maternity Leave.


Yes it could. But I haven't given it any thought. Now that you see a better solution, proceed on that path. Just give every step a thorough thinking.

Quote:
When I started this job the database had already been developed by someone obviously ignorant of any design knowledge. Besides not even being 1NF there were no relationships between the tables. Shocked


As is often the case, unfortunately. The only winner is you, if you are a hired hand to fix it Laughing If you are the unlucky employee who's been ordered to clean up the sh*t; beware not to be blamed for it, in stead of the real guilty one.

Best of luck with your fixes Exclamation

Edit:

A few thoughts, since you mentioned using ENGAGEMENT for different trackings than only begin/end dates:

I originally responded to the problem of NULLs, and you ended up seeing a possibility for the solution to other issues as well. I see where you're at.

Of course the ENGAGEMENT table will have 1 row for the begin date, and then another row (only) when an end date happens. This is of course removing all your initial (perfectly rightful) concerns about the NULL issue, as well as enabling an employee to come back at a later time. It also enables tracking in time: How many come back to work again, avg. length of employment, etc. etc. etc. Lots of niceties here..

In addition, if I am correct, you want to introduce an ENGAGEMENT TYPE, being (so far): Begin, End, Maternity etc. This opens for a richer environment, and also for the (correct) assumption that an employee can have several ENGAGEMENTs at the same time: She is of course still employed while in maternity leave. Extend ENGAGEMENT TYPE to include what you want, really. This really broadens the design, not Question Wink

But it also gives you a (small) challenge regarding what should be the primary key Laughing

I suppose this was more or less your "lightbulb" Question

PS: Show this exchange to your boss, for preventive measures. DS.
_________________
All the best,
Alf
Forum Admin
Light travels faster than sound: That's why so many people appear bright until you hear them speak...
www.databasedesign-resource.com
The Database Normalization eBook
View user's profile Send private message Visit poster's website

  
Author Message
sak
User


Joined: 20 Jan 2010
Posts: 3

PostPosted: Thu Jan 21, 2010 7:27 pm    Post subject: Reply with quote

Fortunately my boss understands.

When I started here they used to kick everybody out of the database (Access 97) for 2 hours so they could run Invoices. It turns out the previous programmer, hereby called DM, had constructed the query as "SELECT * FROM qryInvoice WHERE InvID=1234" in order to print invoice 1234. Unfortunately, qryInvoice was returning a record for every single invoice in the system by going to all the worksheets line by line and calculating totals. Everyday the process would get a little slower because there were more worksheets. My boss would ask DM if all invoices were being calculated because the process was so slow but DM would always answer that only 1 invoice was being returned.

I modified the process to only calculate the invoice in question and the invoice process now only takes a few minutes and people are able to continue in the database. I have proven my worth and my boss feels good about having the correct suspicion behind the performance issue.

I may not know everything about how to work with databases but I know that there are preferred practices and I take what time I can to seek out information. Which is why I am here. Very Happy
View user's profile Send private message

  
Author Message
alf-admin
User


Joined: 07 Nov 2007
Posts: 229
Location: Norway

PostPosted: Thu Jan 21, 2010 9:20 pm    Post subject: Reply with quote

sak wrote:
Fortunately my boss understands.

Very good. A must in order to understand the need for change. Not all bosses possess that understanding. You are lucky.

Quote:
...my boss feels good about having the correct suspicion behind the performance issue.

Even better. Let him/her read up just a little on E-R modeling: It is a great tool for communicating the DB structure and why it should be designed in a certain way (normalized, avoiding NULLs if at all possible). It will educate him a lot, and will give you an educated discussion partner, for the benefit of both of you as well as the company, IMHO. Give him my free ebook on E-R modeling: It was written partly with non-IT people in mind:

http://www.databasedesign-resource.com/entity-relationship.html

No strings attached, except the subscription to my newsletter. But then again, I hardly ever send out a newsletter Smile

Quote:
I may not know everything about how to work with databases but I know that there are preferred practices and I take what time I can to seek out information.

At least you know about asking some right questions, as well as when to start asking. Not bad at all. Too many are mainstream and insignificant...

Quote:
Which is why I am here. Very Happy

He, he. Stay here Wink

PS: You may want to consider doing reverse engineering and remodeling on (even part of) your system, in order to seek out denormalizations, bad design, etc. A (fairly) good and completely free open source E-R modeling tool can be found here:

http://www.fabforce.net/dbdesigner4/
_________________
All the best,
Alf
Forum Admin
Light travels faster than sound: That's why so many people appear bright until you hear them speak...
www.databasedesign-resource.com
The Database Normalization eBook
View user's profile Send private message Visit poster's website

Post new topic   Reply to topic    Database Design Resource Forum: Forum Index -> The newbies section: Basics on DB design All times are GMT
Page 1 of 1
View previous topic :: View next topic  

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Site Build It!

Copyright © 2004-2008 www.databasedesign-resource.com / Alf A. Pedersen
All rights reserved.
All information contained on this website is for informational purposes only.
*Disclaimer: www.databasedesign-resource.com does not warrant any company, product, service or any content contained herein.

Copyright acknowledgement note:

The name Oracle is a trademark of Oracle Corporation.
The names MS Access/MS SQL Server are trademarks of Microsoft Corporation.
Any other names used on this website may be trademarks of their respective owners, which I fully respect.


Powered by phpBB © 2001, 2005 phpBB Group :: Theme & Graphics by GHS :: phpbb Templates available at GemViper.com :: Contents © Database Design Resource Forum: