

Running scripts to audit for certain events or activity is something most DBAs have done, at one time or another. Which solution or combination of solutions is appropriate? It depends on your auditing requirements, time for setting up and maintain audit trails, as well as storage, security and reporting requirements See Concept and basics of Temporal tables in SQL Server 2016 for more information on this feature The feature does require the creation of history tables for each auditing table and requires interaction with T-SQL to view results.
Sql server user activity audit script full#
With temporal tables you can see a full history of changes and it can also be used for recovery purposes. Temporal tables – This is another feature SQL Server has introduced that offers a complimentary solution to CDC. T-SQL knowledge will be required to query the tables and pull information CDC offers much better information and auditing capabilities than Change tracking but lacks a user interface to make viewing and processing the information easy. SQL Server Audit – this feature has been around since SQL Server 2008 and offers rudimentary, “aggregate” auditing capabilities like who made a change and when, but doesn’t offer other information, which today would be considered essential, like what was actually changesĬhange tracking – this SQL Server feature is a step above SQL Server Audit but requires some experience and understanding of the underlying table structures and only tracks changes to the primary key, making it not so useful for anything other than very superficial auditsĬhange data capture (aka CDC) – this is SQL Server’s improvement on Change tracking and is available in the Standard edition since SQL Server 2016. Read more about this here Is this the end of SQL Profiler? SQL Server Profiler and SQL Server traces – this has been the go to technology for auditing in SQL Server for years but it tends to produce voluminous amounts of information and is slated to be deprecated. See the article Read a transaction log, for more information on various solutions But log files are notoriously difficult to read and even when they can be the data isn’t organized for easy consumption and much of it is in hexadecimal format. There is no additional overhead as this is already a built in process in SQL Server. It will record everything that occurs, which lends itself well to purposes like auditing. SQL Server transaction logs – The transaction log in SQL Server is like the black box of an airplane. Note: To automatically add template based trigger based DML (and DDL) auditing to SQL Server databases – see ApexSQL Trigger They aren’t recommended for high throughput or bulk insert tables/operations and maintenance of a trigger based layer can be time consuming. Triggers are an intrusive technology and can throw errors to your client applications when they break. Triggers lend themselves to full customization allowing users to build their own auditing information repositories. They can be set up easily and track a variety of information. SQL Server triggers – these have been a staple for years. Also, there is no means for before-and-after auditing to compare new and old values for updates. Extended events can audit a wide range of actions, but suffers from some deficiencies like not being able to provide information on what was deleted or inserted. SQL Server Extended Events – as the ultimate replacement for SQL Server profiler and traces, extended events offer several advantages including built in GUI tools and potentially better performance. But, in addition to being time consuming, it will be virtually impossible to scale this to all possible auditing events
Sql server user activity audit script manual#
Manual auditing – this might involve a set of queries and possibly reports to track activity per table, transactions by users, recent changes to sensitive tables etc. SQL Server auditing can be broken into several techniques: Organizations are now tasked with auditing access to records, reporting suspicious and potentially malicious activity, forensically auditing data changes, as well are tracking login attempts, security changes and much more.


SQL Server auditing has gone from a nice to have to a legal requirement, especially following new legislation like HIPAA and GDPR.
