Whether or not you should store the age as a value in a column in the table
is a question of functional dependence.
1. If the table is modelling people then the age is not functionally
dependent solely on the key of the table, but also on the date of birth, so
is redundant as (a) it can be computed at any time from the date of birthand
(b) it will contain inconsistent data if not updated as time passes. The
table is consequently not normalized to Third Normal Form.
2. If on the other hand the table is modelling something such as an event in
a person's life then it is functionally dependent solely on the key of the
(events) table, so is not redundant. However, a more usual approach insuch
a case would be to store the date of the event, in which case the age canbe
computed from the event date and the person's date of birth, so to store the
age as well as the event date would again be redundant, and once again the
table would consequently not normalized to Third Normal Form as in this case
the age is functionally dependent on the combination of the key and a non-key
column (the event date).
If scenario 2 above is what you are handling here, and you opt to store the
age at the time of the event rather than the date of event the simply allow
the age column to contain Nulls.
If you wished to adhere fundamentally to the theoretical principles of the
relational model, and prohibit Nulls altogether, then the solution is to
store the date of birth in a separate related table, in which case rather
than having a Null date of birth there would be no row in the related table.
The same goes for age in scenario 2. This would in my view be taking a
ridiculously purist approach, however.
Ken Sheridan
Stafford, England
Hi guys
Thanks for your replies so far
For the form purposes, I calculate age 'now' and age as at 1/1/this
year, neither of them are database fileds as such, just useful info
for the person using the form, *if* the optional date of birth happens
to be entered on the table for that person.
the function is as follows (which I probably copied from the web)
Function Age(varDOB As Variant, Optional varAsOf As Variant) As
Variant
'Purpose: Return the Age in years.
'Arguments: varDOB = Date Of Birth
' varAsOf = the date to calculate the age at, or today
if missing.
'Return: Whole number of years.
Dim dtDOB As Date
Dim dtAsOf As Date
Dim dtBDay As Date 'Birthday in the year of calculation.
Age = Null 'Initialize to Null
'Validate parameters
If IsDate(varDOB) Then
dtDOB = varDOB
If Not IsDate(varAsOf) Then 'Date to calculate age from.
dtAsOf = Date
Else
dtAsOf = varAsOf
End If
If dtAsOf >= dtDOB Then 'Calculate only if it's after
person was born.
dtBDay = DateSerial(Year(dtAsOf), Month(dtDOB), Day
(dtDOB))
Age = DateDiff("yyyy", dtDOB, dtAsOf) + (dtBDay > dtAsOf)
End If
End If
End Function
Hope the extra info helps...