Synchronizing Data with change tracking

Source: Internet
Author: User
Tags create database

SQL Server 2008 introduces change tracking, a lightweight solution that provides an efficient change-tracking mechanism for applications. Typically, to enable an application to query for changes to data in the database and to access information related to those changes, the application developer must implement a custom change tracking mechanism. Creating these mechanisms usually involves a number of tasks and often involves using triggers, timestamp columns, and new table combinations to store trace information, as well as the use of custom cleanup procedures.

With change tracking, you can easily write the application of synchronized data, and here is an example of using change tracking to implement one-way data synchronization.

1 . setting up an example environment

-- ====================================================

--Test the database

Use master;

Go

CREATE DATABASE db_test;

Go

--Enable change tracking

ALTER DATABASE db_test SET

Change_tracking = On (

Auto_cleanup = ON,--turn on automatic cleanup options

Change_retention = 1 HOURS--Data retention is 1 o'clock

);

ALTER DATABASE db_test SET

Allow_snapshot_isolation on; --Allow the SNAPSHOT transaction isolation level to be used in the test database

Go

-- ====================================================

--Test the table

Use Db_test;

Go

--A. Synchronized source table

CREATE TABLE Dbo.tb_source (

pk_id int IDENTITY

PRIMARY KEY,

col1 int,

col2 varchar (10),

Col3 nvarchar (max),

COL4 XML

);

Go

--Enable change tracking

ALTER TABLE Dbo.tb_source

ENABLE change_tracking

With (

track_columns_updated = on--Log Update column information

);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.