ssms2012-触发器单步调试

1 创建trigger

CREATE TRIGGER [dbo].[updataAlarmLevel]
ON [dbo].[Alarm_Alarm_Info]
AFTER INSERT, UPDATE
AS
BEGIN
    if update(transferNum) or update(potentialLoss)
    declare @transferNum int;
    declare @potentialLoss decimal(20,2);
    declare @alarmLeve int;
    select @transferNum=transferNum from inserted;
    select @potentialLoss=potentialLoss from inserted;
     if @transferNum > 1000 or @potentialLoss > 100000000
        set @alarmLeve = 1;--特大型警情
    else if 500 < @transferNum and @transferNum <= 1000 or @potentialLoss <= 100000000 and @potentialLoss > 50000000
        set @alarmLeve = 2;--大型警情
    else if 100 < @transferNum and @transferNum <= 500 or @potentialLoss > 5000000 and @potentialLoss <= 50000000
        set @alarmLeve = 3;--中型警情
    else if @transferNum <= 100 or @potentialLoss <= 5000000
        set @alarmLeve = 4;--小型警情
     update Alarm_Alarm_Info set alarmLevel = @alarmLeve where id = (select id from inserted);

END

2 创建存储过程

CREATE    proc [dbo].[alarm_procUpdate]
as 
begin
 update Alarm_Alarm_Info set transferNum=66 where id='0b64bdb8-a069-4594-881b-fc08531869fe'--(更新表数据触发上面的触发器

end

3 打开ssms新建查询

exec [dbo].[alarm_procUpdate]

4 点击调试按钮

    F11实现单步调试

ssms2012-触发器单步调试_第1张图片

    继续F11

ssms2012-触发器单步调试_第2张图片

    继续F11实现单步调试trigger

ssms2012-触发器单步调试_第3张图片

你可能感兴趣的:(sqlserver)