Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle who care about creating, delivering, and maintaining software responsibly. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

my question would be can age be considered a composite attribute? Because name is a composite attribute and it can be divided into first name, middle name and last name. And therefore can age be a composite attribute since you can divide it into years, months and then days?

share|improve this question
4  
You can divide a last name into letters, but that doesn't make it a composite attribute. Would you ever want to know only the "months" component of someone's age? – Kilian Foth 14 hours ago
8  
So you store your age (say 20 years, 10 months, 5 days) in the DB and now you're always that old? – Thomas Kilian 14 hours ago
1  
@Blrfl Getting philosophic? Age is always dynamic. "Age at" is static, though pointless as you can calculate it from the birthday (which is definitely static). – Thomas Kilian 12 hours ago
8  
Please read Falsehoods Programmers Believe About Names as you seem to be believing some falsehoods about names. – Lars Viklund 11 hours ago
10  
Please don't store age in the database... Store Birth Date sure, but not age! – Milney 10 hours ago

Can age be a composite attribute? No. age is a function of birthdate and now.

age = now - birthdate

So, what about birthdate? Can it be a composite attribute?

Yes, it can, but it only makes sense to store dates as a composite in data warehousing situations.

Often, when warehousing data, you would store year, month, and day as separate things to make it easier to write queries such as

How many people were born in March?

Or

Of all the people born in 1982, how many have blue eyes. How does that compare to April 1992?

You'd also likely have a table that maps dates to quarters, so you could ask things like:

How do birth rates compare between Q1 and Q2 over the last decade?

These are contrived examples, but hopefully illustrate the point. I'd recommend doing some research on "star schema" databases and "slowly changing metrics".

share|improve this answer
    
The questions "Can age be a composite attribute" and "Can age be stored as a composite" are completely unrelated, until one starts to mutilate her logical data model to better fit her physical data model for performance purposes. – Joker_vD 9 hours ago
3  
@Joker_vD as always, it depends. Is this for a transactional db underneath an application? Then no, don't do this. Is it warehoused for reporting where no general purpose language will consume the data? Ok, yup. Optimize the storage for that. – RubberDuck 9 hours ago

Yes, you can store Age as a composite of year, month, date, hour, minute, second in the database if you want to.

However this is probably not a good idea in most cases, because Age can be derived from other values that are usually preferable to have stored in the database. The main reason is that it is better to store birthdate rather than Age; because birthdate is constant but Age depends on the current time. As soon as you save your Age, (unless it is some kind of value for "Age at a certain time", rather than dynamic age) then it will be increasingly incorrect over time.

Storing data that can be derived from other pieces of data is also a violation of some levels of Normal Form and can lead to issues such as data redundancy and inconsistency.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.