on Delete Trigger

  • Good day,

    I want to create a trigger on table sy00500 that will backup the row being deleted from sy00500 into an audit log table before the delete happens.

    How best to do this?

  • - Think of te consequences of auditing this way (data volume)

    - Check "create trigger" in BOL

    e.g.

    create

    trigger trg_D_yourtable on yourowner.yourtable

    AFTER

    DELETE

    AS

    INSERT INTO yourowner.yourtable_Auditlog

    -- column-mapping must be the same !! (or you'll have to state every column)

    SELECT *

    from deleted  -- = object that contains your deleted row(s) data

    GO

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Thank you very much for the prompt reply.

    I was getting stuck with the insert statement (didnt read BOL properly about the 'deleted' table) so i was inserting from the originating table, but getting around 150 000 records in my audit table!!!

    Take care!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply