locked
Update Trigger RRS feed

  • Question

  • Please create an update trigger on the following tables:

     

    SalesDWReference.etl.LookupFlavor

    SalesDWReference.etl.LookupSegment

    SalesDWReference.etl.LookupSpecies

     

    I would like the trigger to update the UpdatedDate and UpdatedBy fields whenever a record is updated.  Please use SUSER_SNAME() as the source for the UpdatedBy field

    Thursday, August 25, 2011 4:06 PM

Answers

  • try below and same you should implement for other 2 tables also
    
    Create trigger trgUpdateNameAndDateTIme on SalesDWReference.etl.LookupFlavor
    after insert
    as
    Begin
    
    declare @id int
    
    select @id = yourIdColumn from Deleted;
    
    update SalesDWReference.etl.LookupFlavor
    set UpdatedBy = SUSER_SNAME(),
    UpdatedDate = getdate()
    where yourIDColumn = @id
    
    End
    
    


    Thanks & Regards Prasad DVR
    • Marked as answer by ravi3005 Wednesday, August 31, 2011 4:15 PM
    Thursday, August 25, 2011 4:24 PM

All replies

  • try below and same you should implement for other 2 tables also
    
    Create trigger trgUpdateNameAndDateTIme on SalesDWReference.etl.LookupFlavor
    after insert
    as
    Begin
    
    declare @id int
    
    select @id = yourIdColumn from Deleted;
    
    update SalesDWReference.etl.LookupFlavor
    set UpdatedBy = SUSER_SNAME(),
    UpdatedDate = getdate()
    where yourIDColumn = @id
    
    End
    
    


    Thanks & Regards Prasad DVR
    • Marked as answer by ravi3005 Wednesday, August 31, 2011 4:15 PM
    Thursday, August 25, 2011 4:24 PM
  • duplicated thread -
    http://uk.linkedin.com/in/ramjaddu
    Thursday, August 25, 2011 4:29 PM
  • Dont post duplicate threads... by the way your question is already answered in the earlier one by Naomi.
    Nothing is Permanent... even Knowledge....
    My Blog
    Thursday, August 25, 2011 5:38 PM