SQL 断言问题
表如下:
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
000012012-09-262012-09-30北京
000012012-10-262012-10-30北京
000022012-10-062012-10-15上海
000022012-10-202012-10-30广州
000032012-10-162012-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
)
))