复制内容到剪贴板
代码:
/*数据字典*/
create table a(
aid int,
amax int,
amin int
)
create table b(
bid int identity primary key,--bid自动增加
aid int,
btotal int
)
/*触发器*/
create trigger b_in
on b
for insert,update
as
declare @aid int,@max int,@min int
select @aid=aid from inserted
select @max=max(btotal) from b where aid=@aid
select @min=min(btotal) from b where aid=@aid
if (select count(*) from a where aid=@aid)=0
begin
insert into a values(@aid,@max,@min)
end
else
begin
if @max>(select amax from a where aid=@aid)
begin
update a set amax=@max where aid=@aid
end
if @min<(select amin from a where aid=@aid)
begin
update a set amin=@min where aid=@aid
end
end