需要添加约束:日期加10天 [英] Need to add constraint: date plus 10 days

查看:200
本文介绍了需要添加约束:日期加10天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向表中添加约束,以便将其中一列显示为当前日期加上10天。这是我到目前为止我尝试的(我是新的SQL):

  ALTER TABLE orders 
ADD CONSTRAINT default_date
DEFAULT DATEADD(DAY,10,required_date)FOR required_date

Halp! p>

编辑:我也尝试过了:

  
ALTER COLUMN required_date
ADD CONSTRAINT required_date_plus_ten
DEFAULT DATEADD(DAY,10,required_date)


b $ b

编辑:感谢ypercube&我的同学。最终代码是:

  ALTER TABLE orders 
ADD CONSTRAINT default_date
DEFAULT(DATEADD ,'required_date'))for required_date;


解决方案

SQL Server中的语法, code> DEFAULT 的值为:

  ALTER TABLE orders 
ADD CONSTRAINT required_date_plus_ten
DEFAULT DATEADD(day,10,GETDATE())
FOR required_date;

SQL-Fiddle


I'm trying to add a constraint to a table so that it displays one of the columns as the current date plus 10 days. Here's what I've tried so far (I'm very new to SQL):

ALTER TABLE         orders
ADD CONSTRAINT  default_date
DEFAULT         DATEADD (DAY,10,required_date) FOR required_date

Halp!

Edit: I've also tried this now:

ALTER TABLE         orders
ALTER COLUMN        required_date
ADD CONSTRAINT      required_date_plus_ten
DEFAULT             DATEADD (DAY,10,required_date)

Edit: Thanks to ypercube & my classmate. The final code is:

ALTER TABLE       orders
ADD CONSTRAINT    default_date
DEFAULT           (DATEADD (DAY,10,'required_date')) FOR required_date;

解决方案

The syntax in SQL-Server, for adding a DEFAULT value to an existing column is:

ALTER TABLE     orders
ADD CONSTRAINT  required_date_plus_ten
DEFAULT         DATEADD(day, 10, GETDATE())
FOR             required_date ;

Tested in SQL-Fiddle

这篇关于需要添加约束:日期加10天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆