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
87 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:ScottPletcher
ScottPletcher 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 45

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now