SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Change Tracking - 2008


Change Tracking - 2008

Author
Message
nitesh_rd
nitesh_rd
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 96
Comments posted to this topic are about the item Change Tracking - 2008
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12284 Visits: 8926
Nice example of change tracking.

You mention
is designed to work with Sync Services for ADO.NET.
but the article lacks the example or refs to do so.

e.g. as a starting point:
Change Tracking and Sync Services for ADO.NET

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Koenraad Dendievel
Koenraad Dendievel
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 136
This is not a replacement to track complete history of changes (who dunnit) but more a 'do i have the latest version'-tool(replication/synchronisation)

To track changes I usually add a trigger and a valid_time_table for important tables.

A valid time table is a copy of the original table with these added columns

ID_Historiek int Unchecked Primary Key
audit_StartTime datetime Unchecked -> timestamp of change
audit_StartUser varchar(50) Unchecked
audit_EndTime datetime Checked -> default '9/9/9999' -> timestamp of next change
audit_EndUser varchar(50) Checked -> default null

The basic layout of the trigger on the table

IF UPDATE(field_you_want_to_track_changes_for)
or update ()
or not exists ( select 1 from hist_PDO_historiek where ID_PDO in (select ID_PDO from inserted)
BEGIN

UPDATE hist_PDO_Historiek
SET audit_endtime = (@TrigTime),
audit_enduser = (SUSER_SName())
FROM deleted,
hist_PDO_Historiek
WHERE hist_PDO_Historiek.ID_PDO = deleted.ID_PDO
AND audit_endtime = '9/9/9999'


INSERT INTO dbo.hist_PDO_Historiek ([*All table fields you want a history off*],
[audit_StartTime],
[audit_EndTime],
[audit_StartUser])
SELECT [*All table fields you want a history off*],
@TrigTime,
'9/9/9999',
Suser_Sname()
FROM inserted
END

/*GOTCHA*/
The IF(UPDATE) checks wether the field is mentioned in the update/insert/delete statement , NOT wether the field was actually changed
UPDATE x set field=field from x -> value is not changed but update statement is logged

There is no 'retention period' so without modification/custom cleanup everything remains logged
TIP: You can also do a record based retention(last 10 modifications) instead of time based (last 3 days)

Advantages over change_tracking?
Username information (you could also store applicition/IP/...)
Easier searching in the history (select * from history ...)
You can reconstruct the values of the DB at a certain time since all history lines have a valid_from valid_to

I'm sure change_tracking is more lightweight and causes less locking issues and probably takes less space (only changed values?) but it is not as easy to handle as a triggerbased valid_time_table solution
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12284 Visits: 8926
Koenraad Dendievel (6/18/2012)
This is not a replacement to track complete history of changes (who dunnit) but more a 'do i have the latest version'-tool(replication/synchronisation)

...


Roy Ernest published a great series of articles which discuss the different techniques SQLServer offers ...
Allow me to refer to the last one ( because that one contains the refs to the previous articles w00t )
What, when and who? Auditing 101 - Part 3

CT only handles "it changed" not the who did it part.

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
charles.atwood
charles.atwood
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 82
In the example provided, the select from the change table following the DML below did not appear to reveal the insertion of the EmployeeId 2 or the update to EmpolyeeId 3. I'm only seeing 2 inserts and on delete.... Am I missing something? Thanks!

INSERT INTO tblEmployee Values (1, Null, 'Mike', 'Fields', 1)
INSERT INTO tblEmployee Values (2, 1, 'John', 'Hopkins', 1)
INSERT INTO tblEmployee Values (3, 1, 'Henry', 'III', 1)
Delete tblEmployee Where EmployeeID = 2
Update tblEmployee Set FirstName = 'Suresh', LastName = 'Sankar' Where EmployeeID = 3
padre
padre
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 308
What edition of SQL Server is this available with?
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12284 Visits: 8926
all.

have a look at Features Supported by the Editions of SQL Server 2008

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
seyuboglu
seyuboglu
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 36
In SQL Server 2008 you can use two prepared method to get the changes on a table. One is called as "Change Tracking" and the other is "Change Capturing". With change tracking option you can have the last chage about the record. By using change capturing you can have the history of the changes.

In my project i decided to use the change tracking method. Becaus it is a internal process it is faster. And i don't need to manage change version etc. So, it was good choice in my opinion.

I successfully applied the method to my system. Everything was working well unitill we need to restart our server to fix another isue. When we start the server back, we noticed that backup of the change tracking enabled databases were not working anymore. It was a bug with the chacnge tracking system. When you restart the sql server, cleanup process of the change tracking system is corrupted and some duplicate records remains in "syscommittab" system table. The message was

“Cannot insert duplicate key row in object 'sys.syscommittab' with unique index 'si_xdes_id'. [SQLSTATE 23000] (Error 2601) Failed to flush the commit table to disk in dbid ID due to error 2601. Check the errorlog for more information. [SQLSTATE 42000] (Error 3999) BACKUP DATABASE is terminating abnormally. [SQLSTATE 42000] (Error 3013) The statement has been terminated. [SQLSTATE 01000] (Error 3621). The step failed.”

Workaround of this case is so troublesome. This is a known isue. Check the KB 978839. I applied the service pack 3. But it did it again. At the end, i removed the change tracking implementation. As you guess, it was not easy while the system is used.

I don't suggest to use change tracking system in sql server 2008.
rahulskm
rahulskm
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 6
Excellent post. Thanks Nitesh.
tymberwyld
tymberwyld
SSChasing Mays
SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)SSChasing Mays (612 reputation)

Group: General Forum Members
Points: 612 Visits: 275
First off, nice post, I will start playing with this some more. Also, I do agree with some of the others who have mentioned that this solution does not provide the "who dunnit and when" which is important for SOX or HIPPA auditing. I have used a solution in the past where we just implemented the same trigger on any table we wanted to audit. This trigger would "asynchronously" audit any data changes (even deletes) and publish them using the SQL Server Service Broker. The auditing database could then be centralized whereever we wanted, and if needed, all databases could publish "audits" to the SB channel, and it didn't matter if the auditing database moved to a different server in the future. Again, everything was Async so none of the ETL processing was slowed down. We did not create those god-awful "copy a table and its schema" solutions and just add the same records to them approach I see others doing.



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search