[CODE]create table tt(
id int,
name varchar(10),
prof varchar(20),
comm int
)
insert tt select 1,'小明','讲师',1500
union all select 2,'小强','教授',3900
union all select 3,'小李','副教授',2500
union all select 4,'小陈','普通教师',1000
go
create trigger tri_temp on tt
for update
as
begin
if @@rowcount>1
begin
rollback tran
raiserror ('每次只能更新一条信息',16,1)
return
end
declare @old_prof varchar(20),@new_prof varchar(20)
declare @id int
select @id=id,@old_prof=prof from deleted
select @new_prof=prof from inserted
if update(prof)
begin
if @old_prof='讲师' and @new_prof='副教授'
update tt set comm=comm+500 where id=@id
if @old_prof='副教授' and @new_prof='教授'
update tt set comm=comm+900 where id=@id
end
end
go
select * from tt
update tt set prof='教授' where id=3
select * from tt
drop trigger tri_temp
drop table tt[/CODE]