约束检查条件添加当前日期

时间:2017-03-07 00:16:11

标签: sql-server

我尝试过以下代码

CONSTRAINT employees_hire_date_ck CHECK (WHERE hire_date=NULL THEN curr_date ELSE hire_date END)

如果我的列hire_date在sql server中使用约束检查条件为空,我需要分配当前日期

2 个答案:

答案 0 :(得分:0)

尝试 例如,当hire_date为空时,那就是GETDATE()

ELSE hire_date

END AS hire_date

答案 1 :(得分:0)

我建议为此目的使用计算列或触发器。

,employees_hire_date as case when [hire_date] is null 
                             then curr_date 
                             else hire_date end
相关问题