Last Update: 19 September 2007
Product: StarQuest Data Replicator
Version: 3.30 or later
Article ID: SQV00DR017
This document describes a method for using StarQuest Data Replicator (SQDR) to simulate real-time replication from SQL Server to any database management system that SQDR supports (DB2, Oracle, or SQL Server). This is particularly useful for organizations that use SQL Server editions which do not include the Replication feature, such as the Standard and Workgroup editions.
For best results performing incremental replication from DB2 for iSeries or DB2 for Linux, UNIX, and Windows to SQL Server, use SQDR with SQDR Plus. To download a free trial of SQDR Plus, go to http://www.starquest.com.
This document is intended for SQL Server users who are familiar with the techniques of creating and altering tables. In addition, this solution is designed to work only with source tables in which new records are inserted, but no records are updated or deleted.
All of the SQL Server SQL statements included in the instructions below can be executed in the Query Analyzer (SQL Server 2000) or the Management Studio New Query window (SQL Server 2005).
Following are the general steps that you need to perform. Each step is described in more detail in the Detailed Procedures section.
Add a timestamp column to the SQL Server source table.
The SQL Server source table to be replicated must have a timestamp field. If one does not exist, add a non-nullable timestamp column to the table. The example below adds a non-nullable column called "tscol" to a source table called stable. Execute the following SQL statement changing [database] to the actual name of the source database.
alter table [database].dbo.stable add tscol timestamp not null
NOTE: Do not confuse the timestamp data type with the datetime data type. The timestamp data type is an auto-generated binary value used for "row-versioning." It does not actually preserve the date or time and thus is better suited than the datetime data type for this specific application because it is guaranteed to be a unique value regardless of system date/time changes on the SQL Server system.
Create a SQL Server table to store row identification values.
create table dbo.subtrack (subname varchar(128) not null primary key, curmax binary (8) default 0, lastmax binary (8) default 0)
The subname column will store the name of the SQDR subscription. The curmax column will store the maximum timestamp of the rows in the source table to be replicated to the destination host at the start of the replication. The lastmax column will hold the timestamp value of the last row successfully replicated to the destination host.
- The row must be first initialized with the name of the subscription (to be created later) but afterwards the timestamp values will be maintained by SQL statements executed in the SQDR subscription process. Execute the following SQL statement:
insert into dbo.subtrack (subname) values ('stable')
update [database].dbo.subtrack set curmax = (select max(tscol) from [database].dbo.stable) where subname = 'stable'
update [database].dbo.subtrack set lastmax = curmax where subname = 'stable'
where (stable.tscol > (select lastmax from [database].dbo.subtrack where subname = 'stable')) and (stable.tscol <= (select curmax from [database].dbo.subtrack where subname = 'stable'))
Click the Verify button to verify that the SQL statement does not contain any syntax errors. It is normal at this stage for the result set returned using this criteria to be zero.
delete from [database].dbo.stable where tscol <= (select lastmax from [database].dbo.subtrack)
The information in technical documents comes without any warranty. The author(s) or distributor(s) will not accept responsibility for any damage incurred directly or indirectly through use of the information contained in these documents. The information in technical documents may be gathered from various sources, including IBM, Microsoft, and other organizations.