27,579
社区成员
发帖
与我相关
我的任务
分享
create trigger tri on A for insert
as
begin
update B
set passband=i.examband
from inserted i
where B.xuehao=i.xuehao and i.score>425
end
go
--在表A中插入数据,当A中的examband=0且score>425的时候更新表B中的passband为0,当A中的examband=1且score>425的时候更新表B中的passband为1
--当上面2个条件都不满足的时候将B表的passband更新为-1
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'trA' AND type = 'TR')
DROP TRIGGER trA;
GO
Create Trigger trA
On A
for Insert
As
begin
update B set passband=0 where exists(select * from Inserted where examband=0 and score>425);
update B set passband=1 where exists(select * from Inserted where examband=1 and score>425);
update B set passband=-1 where not exists(select * from Inserted where examband in(0,1) and score>425);
end