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
100 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 47

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert in derived column 7 31
Check number of row prior to displaying gridview 10 36
This query failed in sql 2014 5 33
Passing Parameter to Stored Procedure 4 24
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

831 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