0

I need to create a table with a column named age to calculate the age from the birth of date and I am using the following code:

CREATE TABLE AgeTable
  ( 
     ID  INT(3), 
     DOB    Date, 
     Age int(100) AS (TIMESTAMPDIFF (YEAR, DOB, CURDATE()))
  );

I get the following ERROR!!!

Error Code: 3763. Expression of generated column 'Age' contains a disallowed function: curdate.

Any help please, btw I am using MySQL.

Thanks in advance.

Ali
  • 1
  • 1
  • 2
    WHY. Next year the Age will be wrong. This is a bad design decision – RiggsFolly May 17 '21 at 15:56
  • Always get age from a select statement or create a view, never hard code age. – d0little May 17 '21 at 15:59
  • This is not a duplicate question as I need to add a generated column to calculate the age without using SELECT STATMENT. Tq – Ali May 17 '21 at 16:07
  • Please read the paragraph [here](https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html) after the statement "Generated column expressions must adhere to the following rules. An error occurs if an expression contains disallowed constructs.". And, when you are looking at the docs, try to find out if it is useful to specify `int(100)` as a datatype for a column..... – Luuk May 17 '21 at 16:36

0 Answers0