1

I have a table created for our customers. It includes Date of Birth field. And I would like to add another field called Age and would like to make it auto increment the age.

Is it possible to do that in SQL database?

Thank you so much for any help in advance!

  • The question is not clear.. **auto increment the age.** what does that mean??/ – Rahul Tripathi Sep 07 '13 at 08:21
  • 2
    if you create a view then you can create a field called age that is derived from an equation – DevZer0 Sep 07 '13 at 08:24
  • 2
    My guess is the OP wants to store current age along with date of birth in DB. There is no need to store it separately. While fetching records from this table, you can generate those current age values on the fly using sql date functions – rakeshjain Sep 07 '13 at 08:25
  • you can schedule a procedure may be in every day and this procedure will calculate and increment age. – Biswajit Maji Sep 07 '13 at 08:28
  • @Biswajit How do I do like you said, please guide me! I want to try like you said! – Myanmar Songs Sep 07 '13 at 08:33
  • here you can an idea of schedule- http://stackoverflow.com/questions/3070277/mysql-event-scheduler-on-a-specific-time-everyday http://stackoverflow.com/questions/6560639/how-to-schedule-a-stored-procedure-in-mysql – Biswajit Maji Sep 07 '13 at 08:43

1 Answers1

4

Well, you can calculate each time you fire select query.

SELECT name, birth, TIMESTAMPDIFF(YEAR,birth,CURDATE()) AS age FROM your_table;
Dhwani
  • 7,484
  • 17
  • 78
  • 139