Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6808909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:00:51+00:00 2026-05-26T20:00:51+00:00

Disclaimer: I am unable to implement this properly in the application, as the application

  • 0

Disclaimer: I am unable to implement this properly in the application, as the application I’m working on doesn’t do data access in a consistent way, and refactoring effort would be too great for the scope of the project and coming deadline.

How would I go with implementing a SQLCLR Trigger for Audit Trail? I would like it to be as simple as possible, and as easy to remove and replace with proper implementation later as possible.

I’m planning to write my audit to a single table (the database is not very write heavy), having columns like:

  • Timestamp (datetime) – when the change happened?
  • Username (varchar) – who made the change?
  • AffectedTableName (varchar) – which table has been affected?
  • AffectedRowKey (varchar) – this will be either a simple or compound key like (Id=42, A=4,B=2)
  • OperationType (char(1)) – either I, U or D for insert, update and delete respectively.
  • InsertedXml (xml) – xml-serialized row (SELECT * FROM INSERTED FOR XML AUTO)
  • DeletedXml(xml) – xml-serialized row (SELECT * FROM DELETED FOR XML AUTO)

I’m planning to query and resolve this data to a user-readable form in the application. I’m planning to implement this as a database trigger, written using SQLCLR. I can see 2 possible approaches:

  • Implement this entirely as SqlTrigger method:
  • Implement this as a SqlProcedure method taking parameters:
    • schemaName
    • tableName
    • insertedXml
    • deletedXml

I will appreciate any constructive criticism and suggestions. My limitation is that I have to implement the audit at the database level using triggers, and I want it to be as maintainable (read: removable and replacable) as possible. Also ideally, I don’t want to have hundreds of triggers with exactly the same body, in case I have to modify them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:00:52+00:00Added an answer on May 26, 2026 at 8:00 pm

    I’ve been using a variation of this script to create audit triggers from some of my projects for awhile now with great results:

    http://www.simple-talk.com/sql/database-administration/pop-rivetts-sql-server-faq-no.5-pop-on-the-audit-trail/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer : This is for a semester project that I am currently working on.
Disclaimer: This is not actually a programming question, but I feel the audience on
Disclaimer: This is for a homework assignment, but the question is not regarding the
DISCLAIMER: The following code is not something I would ever use in a real
Disclaimer This is not strictly a programming question, but most programmers soon or later
Disclaimer: I realize I can generate this at runtime in Java, this was needed
Disclaimer : I realize asking Why doesn't my regular expression work is pretty amateur.
Disclaimer : I'm new to web development. Scenario : I've built an application using
Disclaimer, I'm not a PHP programmer, so you might find this question trivial. That's
Disclaimer: I'm working on Euler Problem 9. I'm adding up some pretty large numbers,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.