How to determine if insert or update

后端 未结 5 694
庸人自扰
庸人自扰 2020-12-07 00:03

Whenever INSERT is happened in the CUSTOMER table,I need to call the \"StoredProcedure1\"and UPDATE is happend in the CUSTOMER table,I need to call the \"

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 00:35

    The easiest way to solve this problem would be to have two triggers, one for the insert and one for the update.

    CREATE TRIGGER InsertNotifications ON CUSTOMER
    FOR INSERT
    AS
    BEGIN
    DECLARE @recordId varchar(20);
    set @recordId= new.Id;
        //if trigger is insert at the time I call to SP1
            EXEC StoredProcedure1 @recordId
    
    END
    
    CREATE TRIGGER UpdateNotifications ON CUSTOMER
    FOR UPDATE
    AS
    BEGIN
    DECLARE @recordId varchar(20);
    set @recordId= new.Id;
        //if trigger is Upadeted at the time I call to SP2
            EXEC StoredProcedure2 @recordId
    END
    

提交回复
热议问题