Solved

Better way to handle 'auditing' columns such as created_by, created_dt, last_updated_by, last_updated_dt

Posted on 2014-11-19
5
115 Views
Last Modified: 2015-05-24
Hi guys

In a previous question I made the below comment, which resulted in feedback that there are better ways to handle these values, to include splitting them into a separate table.

As a general rule any table I design that has data entry, I'll add four 'auditing' columns to it that populate via INSERT and UPDATE triggers:
  created_dt  -  datetime - of the entry
  created_by_id -  varchar(30) - SUSER_NAME() of the person creating it
  last_updated_dt  -  datetime - of any insert-update
  last_updated_by_id - varchar(30) - SUSER_NAME() of the person updating it.

Points for advice on a better way to handle this.

Thanks.
Jim
0
Comment
Question by:Jim Horn
5 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 40452874
Have you tried CDC feature yet ?
0
 
LVL 65

Author Comment

by:Jim Horn
ID: 40452896
No.  Have you implemented CDC, and if so how did you do it, and what were the benefits?
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 50 total points
ID: 40452965
I have implemented on  couple of database servers to catch the data capture,  this is inbuilt feature of sql server, which captured the data changes on TL , so it will be faster compared to triggers.  In your case I realized that, you need to capture the User who made the changes too, which I am afraid, cant be done thru CDC;  every thing related to the changed data can be audited thru CDC.
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 225 total points
ID: 40452997
Change Tracking is more lightweight and can tell you when a change occurred for a given row ... but not what was changed, which CDC can do.  CT can't directly tell you "who" either.  

Default constraints could provide datetime and SUSER_SNAME() for created.
0
 
LVL 49

Accepted Solution

by:
Vitor Montalvão earned 225 total points
ID: 40454452
In a separate table you can add more features as for example if the operation was an Insert, Delete or Update, so you can also track deletes.
At the same table you can't track deletes and you don't have an history, only the last change.
Also, you can put the separate table in another file, filegroup or even database. I think it's a more flexible option but it always depends on the goal of the solution that you want.
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question