用如下方法创建约束:
1、创建测试表
create table test
(id int,
tdate datetime);
2、添加约束
alter table test add constraint CN_tdate check (tdate < getdate());
3、执行语句测试:
a、插入一个小于当前日期的数据(插入成功)
insert into test values (1,'2015-09-22');
执行结果:
b、插入一个大于(或等于)当前日期的数据(插入失败)
insert into test values (2,'2015-09-28');
执行结果:
--dd 为列名
--Table_1 为表名称
ALTER TABLE dbo.Table_1 ADD CONSTRAINT
CK_Table_1 CHECK (dd