?
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
Medium Priority
?
146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 75

Expert Comment

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

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 200 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 900 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 51

Accepted Solution

by:
Vitor Montalvão earned 900 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

770 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