Loading...
 
JoiWiki » Developer » Databases » SQL Scripts » SSMS Stored Procedure - Create Audit Table and Trigger SSMS Stored Procedure - Create Audit Table and Trigger

SSMS Stored Procedure - Create Audit Table and Trigger

SSMS Stored Procedure - Create Audit Table and Trigger

This isn't a particularly glamorous function of a database but having a record of that changes that have been made to a record over time and being able to reinstate previous data can be incredibly useful when things go wrong (and you've been quick or lazy with your transactions). SSMS 2016 introduces Temporal Tables which seem incredible but I've not had the chance to use 2016 professionally and given the speed at which certain industries update their database support that might be a long way down the road!. So for now a 2008 R2 compliant solution that will create an audit table (throughout the code I refer to this as a Data Change History table or DCH) that mirrors the structure of the table that is named by parameter and a trigger for that table that will insert data into the audit table any time the data in the parent table has changed:

Created by JBaker. Last Modification: Thursday April 18, 2019 15:33:04 BST by JBaker.

Developer