SQL Server Management Studio将在5天后生成默认日期

时间:2021-09-13 17:13:15

I am working on a database and I need to make the default value for a date column to be 5 days from the current date.

我正在处理数据库,我需要将日期列的默认值设置为距当前日期5天。

Would using getdate() + 5 work?

会使用getdate()+ 5吗?

I'm using the GUI at the moment.

我目前正在使用GUI。

Would a query like this work?

这样的查询会起作用吗?

ALTER TABLE Order 
  ADD CONSTRAINT DF_Order DEFAULT GETDATE()+5 FOR DateofOrder

Thanks.

1 个解决方案

#1


1  

Yout can tryout DateAdd function for adding days to date

Yout可以试用DateAdd函数来添加日期

Example

DATEADD(day,1,@datetimevar/column)

try like this

试试这样

create table t(
  i int,
  d datetime default (dateadd(day,5,getdate()))
)

#1


1  

Yout can tryout DateAdd function for adding days to date

Yout可以试用DateAdd函数来添加日期

Example

DATEADD(day,1,@datetimevar/column)

try like this

试试这样

create table t(
  i int,
  d datetime default (dateadd(day,5,getdate()))
)