terça-feira, 1 de janeiro de 2008

Change Tracking on SQL 2008

One feature that will be on SQL Server's next release is database change tracking.

it allows to create applications that track changes in databases without using mechanisms like replication or triggers and so on.

How it works?

 

After a DML operation is made on database the following actions happen:

  • Performs the data insert, update, or delete operation.
  • Adds a row to an internal change tracking table. There is one internal table for each user table that uses change tracking.
  • so the change tracking is based on logging information in data tables to capture what is happening.

    There is a bunch of functions to check the data that is been tracked *:

    CHANGETABLE (CHANGES)

    Returns tracking information for all changes to a table that have occurred since a specified version.

    CHANGETABLE (VERSION)

    Returns the latest change tracking information for a specified row.

    CHANGE_TRACKING_MIN_VALID_VERSION()

    Returns the minimum version that is valid for use in obtaining change tracking information from the specified table when you are using the CHANGETABLE function.

    CHANGE_TRACKING_CURRENT_VERSION

    Obtains a version that is associated with the last committed transaction. You can use this version the next time you enumerate changes by using CHANGETABLE.

    CHANGE_TRACKING_IS_COLUMN_IN_MASK

    Interprets the SYS_CHANGE_COLUMNS value that is returned by the CHANGETABLE(CHANGES …) function.

    WITH CHANGE_TRACKING_CONTEXT

    Enables the specification of a change context, such as an originator ID, when an application changes data.

     

    * Excerpt from books online, pre-release material.

     

    there is new database options for the DBA control the change tracking feature (enabled or not) and  the period of retention for the information about the changes.

    (check on database properties, change tracking tab)

    0 comentários: