I would like to set the Default value for a column to Current Time + 6hrs

末鹿安然 提交于 2019-12-08 09:39:52

问题


I have a column in an Sql server express table called DepTime which has a Time data type.

I would like to set the Default value for this column to Current Time + 6hrs.

How can I do this.

Thank you


回答1:


here is an example for a temporary table:

CREATE TABLE #tmp (
   test varchar(30),
   DepTime datetime  DEFAULT DATEADD(hour, 6, GETDATE())
);

or if you already have a table:

ALTER TABLE SomeTable 
   ADD CONSTRAINT DF_SomeTableSomeName 
   DEFAULT DATEADD(hour, 6, GETDATE()) FOR DepTime;


来源:https://stackoverflow.com/questions/28591389/i-would-like-to-set-the-default-value-for-a-column-to-current-time-6hrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!