MSSQL 触发器
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
if exists(select * from sysobjects where [name]='Trig_MemberGropu')
drop trigger Trig_MemberGropu
go
create trigger Trig_MemberGropu
on Member
for UPDATE
AS
declare @Score int
declare @MemberID int
IF UPDATE (Score)
select @Score = Score from inserted
select @MemberID= memberID from inserted
if @Score>15000
begin
update Member set groupid=5 where MemberID=@MemberID
end
else if @Score>8000
begin
update Member set groupid=4 where MemberID=@MemberID
end
else if @Score>5000
begin
update Member set groupid=3 where MemberID=@MemberID
end
else if @Score >3000
begin
update Member set groupid=2 where MemberID=@MemberID
end
drop trigger Trig_MemberGropu
go
create trigger Trig_MemberGropu
on Member
for UPDATE
AS
declare @Score int
declare @MemberID int
IF UPDATE (Score)
select @Score = Score from inserted
select @MemberID= memberID from inserted
if @Score>15000
begin
update Member set groupid=5 where MemberID=@MemberID
end
else if @Score>8000
begin
update Member set groupid=4 where MemberID=@MemberID
end
else if @Score>5000
begin
update Member set groupid=3 where MemberID=@MemberID
end
else if @Score >3000
begin
update Member set groupid=2 where MemberID=@MemberID
end
简单的更新