存储出生日期.使年龄成为计算列:
CREATE TABLE [Table](
/* Columns */
[DateOfBirth] [date] NULL,
[Age] AS CASE
WHEN DATEADD(year,-DATEDIFF(year,DateOfBirth,CURRENT_TIMESTAMP),CURRENT_TIMESTAMP) < DateOfBirth THEN
DATEDIFF(year,DateOfBirth,CURRENT_TIMESTAMP) - 1
ELSE
DATEDIFF(year,DateOfBirth,CURRENT_TIMESTAMP)
END,
/* Constraints, etc */
)
Run Code Online (Sandbox Code Playgroud)
这样您就不必自己做任何工作.