SQL Server trigger (TRIGGER)-triggers a "go" when updating a few columns of data

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.