数据库中的DOB,一年后我想增加年龄并更新到数据库中

sar*_*mar -4 c# sql-server-2008 winforms

我在数据库中存储出生日期,一年后我想增加年龄并更新到数据库中.

Dam*_*ver 6

存储出生日期.使年龄成为计算列:

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)

这样您就不必自己做任何工作.