 |
Display posts from previous |
 |
 |
Dates and NULLs |
 |
|
 |
|
 |
| Author |
Message |
alf-admin User

Joined: 07 Nov 2007 Posts: 229 Location: Norway
|
Posted: Thu Jan 21, 2010 11:59 am Post subject: |
|
|
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
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 |
|
 |
|
|
 |
|
 |
|
 |
|
 |
| Author |
Message |
alf-admin User

Joined: 07 Nov 2007 Posts: 229 Location: Norway
|
Posted: Thu Jan 21, 2010 3:30 pm Post subject: |
|
|
| 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.  |
As is often the case, unfortunately. The only winner is you, if you are a hired hand to fix it 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
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
But it also gives you a (small) challenge regarding what should be the primary key
I suppose this was more or less your "lightbulb"
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 |
|
 |
|
|
 |
|
 |
|
 |
|
 |
| Author |
Message |
alf-admin User

Joined: 07 Nov 2007 Posts: 229 Location: Norway
|
Posted: Thu Jan 21, 2010 9:20 pm Post subject: |
|
|
| 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
| 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.  |
He, he. Stay here
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 |
|
 |
|
|
|