Skip to content
Advertisement

How to compare old value and new value in triggers and then mark as insert/update/delete in audit table

My Attempt:

When I have inserted one record for ref_id into the table source_Det then in the audit table I am getting two records but ideally, it should check and load only that value which is newly inserted.

Current Output:

Expected Output:

Basically, I need to check two columns ref_id and sys_other. If only ref_id entered by user or modified by user or deleted by user then it should get marked as inserted/updated/deleted into the audit table. And If only sys_other entered by user or modified by user or deleted by user then it should get marked as inserted/updated/deleted into the audit table.

Advertisement

Answer

Why you didn’t listen to my previous suggestion? You should really add new pair of new/old columns into the audit table, not put everything into value_old/value_new because – as you don’t store information what it represents – you’ll have to guess (and that’s the way to problems).

BTW, what will you do if you – in the same statement – modify both REF_ID and SYS_OTHER? You’ll have to check what you did first, and then insert (or not) a row. Too much code for a little benefit.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement