Code Monkey home page Code Monkey logo

sqlserveraudittrigger's Introduction

SqlServerAuditTrigger

Creates audit tables and audit triggers

A cheap version of CDC (https://social.technet.microsoft.com/wiki/contents/articles/7726.sql-server-change-data-capture-cdc.aspx)

Usage

EXEC [dbo].[AuditTrigger] @SourceTableName = N'<table name>', @Deletes = 1, @Inserts = 1, @Updates = 1, @ForceDropRecreate = 1

This will create an audit table for the table specified called <table name>_Audit. It will contain columns that match the existing table along with 3 new columns called transactionid, date and operation. Triggers will be created on <table name> for INSERT, DELETE or UPDATE operations.

If you add a new column to a table you can re-run the above statement to re-create the audit table and triggers and include the new column.

!!! WARNING The existing audit table will be deleted if you add @ForceDropRecreate = 1 !!!

Parameters

Parameter Description
@SourceTableName The table you want to audit
@Deletes 0 or 1 to indicate if deletes should be audited
@Inserts 0 or 1 to indicate if inserts should be audited
@Updates 0 or 1 to indicate if updates should be audited
@ForceDropRecreate 0 or 1. If not specified and audit table or trigger exists you'll get an error
@Schema If you need to specify schema other than dbo

sqlserveraudittrigger's People

Contributors

theorigin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.