SQL Server – How to Store Audit Data in Table

auditsql server

Is there a standardised way to store auditing information constantly to a table for further analyse?

Best Answer

This really depends on what type of information you want to audit. There are a number of ways to collect audit data.

I did an article that overviews audit options here.

But in summary:

  • Successful/Failed logins: This is an instance level setting and is saved to the logs.
  • C2 Auditing and Common Criteria Compliance: This goes a bit overboard in my opinion. It audits a LOT of information. You'll know if you actually need it.
  • Audit columns: These are columns in your table that give you information. CreateDate & ModifiedDate for example
  • Triggers: These are good if you want to log specific information when doing an insert, update or delete on a table. There can be a lot of overhead here and they can be tricky to get right.
  • Tracing: Otherwise known as profiler. This is an older technology that has been deprecated but is still hanging on and will for who knows how long. You can collect all kinds of information here about what was run, by whome, how long did it take, who logged in, who logged out, just about anything happening on your instance. Remember though that the more you collect the more overhead.
  • Extended Events: This is the replacement for traces. Basically the same but with less overhead and more options for data you can collect.
  • Audits: These can be created at a database or server level. They are based on Extended Events but have a different set of information. For example shutting down the instance can be logged. These are meant for when you need to collect audit information in the traditional sense. The data that is collected for an auditor.

You can get a bit more detail from the link above and it has further links in at least a few places for even more detail.