09. Auditing technique

 

Auditing technique



Note on Using Triggers for Auditing

When we handle auditing through triggers in the database, those triggers still run inside the same transaction started by our application. 

That means: Even though the trigger is in the database and our query is from the application, both use the same transactionSo, if something goes wrong and the transaction is rolled back, both the main query and the trigger's audit logic will be rolled back together.

From a performance perspective, it's often better to use an AFTER trigger for auditing (instead of a BEFORE trigger). This way:

  • The database first completes the main query,
  • Then writes to the audit table,
  • All within the same transaction.

This approach keeps our application code clean and can be slightly more efficient since the audit work is handled by the database directly

Comments

Popular posts from this blog

Database - Topics

02. Spring – Creating spring project clone it with GIT step by step.

01. Steps in SQL Query Execution (MySQL)