日期:2014-05-17 浏览次数:20581 次
create table tra
(
nameID char(5) not null,--人名编号
start_time varchar(20),--出差开始时间
end_time varchar(20),--出差结束时间
city varchar(20),--出差的城市
primary key(nameID,start_time)
)
/*
nameID start_time end_time city
00001 2012-09-26 2012-09-30 北京
00001 2012-10-26 2012-10-30 北京
00002 2012-10-06 2012-10-15 上海
00002 2012-10-20 2012-10-30 广州
00003 2012-10-16 2012-10-15 广州
*/
CREATE assertion a_test CHECK (
nameID NOT EXISTS (
SELECT nameID FROM tra AS A
WHERE EXISTS(SELECT * FROM tra AS B WHERE B.nameID=A.nameID AND B.city=A.city AND
DATEDIFF(d,B.start_time,A.start_time)=0 AND DATEDIFF(D,B.end_time,A.end_time)=0
)
))