22,207
社区成员
发帖
与我相关
我的任务
分享
--示例:
create table oo(no int,到达日期 datetime,离开日期 datetime)
go
--创建触发器
create trigger tri_a on oo instead of insert
as
insert into oo select * from inserted a
where not exists(select 1 from oo where no=a.no and 到达日期=a.到达日期 and 离开日期=a.离开日期)
go
--测试
insert into oo select 1,'2008-05-23','2008-05-24'
insert into oo select 1,'2008-05-23','2008-05-24'--插入失败
insert into oo select 1,'2008-05-23','2008-05-25'--插入成功
insert into oo select 2,'2008-05-23','2008-05-24'--插入成功
--查看结果
select * from oo
create trigger tri_a on 表名 instead of insert
as
insert into 表名 select * from inserted a
where not exists(select 1 from 表名 where no=a.no and 到达日期=a.到达日期 and 离开日期=a.离开日期)