SQL update trigger only when column is modified

后端 未结 5 2108
野趣味
野趣味 2020-12-02 08:19

By looking at other examples I\'ve come up with the following but it doesn\'t seem to work as I would like: I want it to only update the modified information if the Qt

5条回答
  •  时光取名叫无心
    2020-12-02 09:01

    Whenever a record has updated a record is "deleted". Here is my example:

    ALTER TRIGGER [dbo].[UpdatePhyDate]
       ON  [dbo].[M_ContractDT1]
       AFTER UPDATE
    AS 
    BEGIN
        -- on ContarctDT1 PhyQty is updated 
        -- I want system date in Phytate automatically saved
        SET NOCOUNT ON;
    
        declare @dt1ky as int   
    
        if(update(Phyqty))
        begin
            select @dt1ky = dt1ky from deleted
    
            update M_ContractDT1 set PhyDate=GETDATE() where Dt1Ky=  @dt1ky     
    
        end
    
    END
    

    It works fine

提交回复
热议问题