CREATE TRIGGER [dbo]. [Updataalarmlevel]
on [dbo]. [Alarm_alarm_info]
After inserts, update– after updating and inserting
As
BEGIN
If update (transfernum) or update (Potentialloss) – event triggered if the Transfernum or Potentialloss two column in the Alarm_alarm_info table changes;
declare @transferNum int;
DECLARE @potentialLoss decimal (20,2);
declare @alarmLeve int;
Select @transferNum =transfernum from inserted;--inserted represents the currently modified data row
Select @potentialLoss =potentialloss from inserted;
If @transferNum > @potentialLoss > 100000000--if conditions do not require {}
Set @alarmLeve = 1;--Extra Large alarm situation
else if < @transferNum and @transferNum <= or @potentialLoss <= 100000000 and @potentialLoss > 500000 00
Set @alarmLeve = 2;--Large alarm situation
else if < @transferNum and @transferNum <= or @potentialLoss > 5000000 and @potentialLoss <= 50000000
Set @alarmLeve = 3;--Medium Alarm situation
else if @transferNum <= or @potentialLoss <= 5000000
Set @alarmLeve = 4;--small alarm situation
Update Alarm_alarm_info Set alarmlevel = @alarmLeve WHERE id = (select id from inserted);
END
SQL Server trigger (TRIGGER)-triggers a "go" when updating a few columns of data