SQL Server Change Data Capture with SAP

Published Mar 13 2019 08:30 AM 935 Views
Microsoft
First published on MSDN on Apr 01, 2010

Hello I am pleased to introduce Clas Hortien as new contributor to this blog site. He is located in the SAP development facilities in Germany. For many years


his focus is to support SAP customers running on SQL Server. Some of you might know him by his contributions to the SDN SQL Server forum. Clas will


start a series of articles looking at new features of SQL Server 2008 in conjunction with SAP. As a first feature we start with “Change Data Capture” and


how it could be leveraged in combination with an SAP system.


Change Data Capture (CDC) provides information about DML changes on a table and a database. By using change data capture, you eliminate expensive


techniques such as user triggers, timestamp columns, and join queries in order to detect changes. Change Data Capture records modifications on tables on


which CDC got enabled. The details of the changes are available in a normal relational table for selection. CDC only tracks the columns which got modified as


we see later on in this article. Change Data Capture functionality is available only in SQL Server 2008 Enterprise, Developer, and Evaluation editions.


So far SAP does not provide any GUI or interface to setup or control the CDC feature. Since Basis release 720, the DBA cockpit provides some monitoring


functionality, mainly to check the status and to see which tables are monitored through CDC.





You can find this new screen in the NON-SAP Features section of the Configuration branch in the DBA Cockpit (see the screenshot).


When you plan on using CDC, you should consider the following limitations and impacts:



  • You may not use CDC, when your SAP System ID (SID) is CDC, because the Change Data Capture feature will interfere massively with your SAP system.

  • CDC will have an impact on CPU and space usage in your system. Especially the space usage can be tremendously, when you monitor multiple tables which a high change rate.

  • Please never ever try to monitor the SAP queuing tables like VBDATA, VBHDR and VBMOD as the amount of data is enormous and not useful anyway.

  • Do not monitor the SAP RFC tables like ARFC*, QRFC* and TRFC*.

  • Never monitor all tables of an SAP system simultaneous.

  • Be extremely selective what table to capture changes on and keep the number of tables limited.


To use CDC you have to manually enable it in a SQL Query Window with the following T-SQL commands:


USE PAX
EXEC sp_cdc_enable_db – enabling it on the DB

-- start it for some tables
EXEC sp_cdc_enable_table 'pax',
'REPOSRC', @role_name = null, @supports_net_changes =1;
EXEC sp_cdc_enable_table 'pax',
'SNAP', @role_name = null, @supports_net_changes =1;
EXEC sp_cdc_enable_table 'pax',
'sap_tabstats', @role_name = null, @supports_net_changes =1;
GO

The first command (sp_cdc_enable_db) enables CDC for the current database. All the necessary structures will be created and the database gets prepared


for the CDC usage.


In the example we started the monitoring for three tables (SNAP – Short dumps, REPOSRC – SAP Report sources, sap_tabstats – DBA Cockpit history


data). With the option @Support_net_changes an additional function gets created, which shows the net changes on the table. By setting the @role_name


option to null the security of the tables which contains the changes is not restricted.


Change Data Capture will create a new schema called ‘cdc’ in the SAP database (therefore never use CDC with a SAP system using the SID of CDC). At least


three additional objects are created in the new cdc schema in the SAP database for each table which is in the scope of CDC:



Object name



Type



Example



fn_cdc_get_all_changes_<schema>_<table name>



function



fn_cdc_get_all_changes_pax_SNAP



fn_cdc_get_net_changes_<schema>_<table name>



function



fn_cdc_get_net_changes_pax_SNAP



<schema>_<table name>_CT



table



pax_SNAP_CT



The table <schema>_<table_name>_CT contains the data of the changed rows. It is an exact copy of the table structure of the source table (e.g. SNAP),


with some additional fields (__$start_lsn, __$seqval, __$operation, __$update_mask) at the beginning of the table.


From SQL Server Books online:



Column name



Data type



Description



__$start_lsn



binary(10)



Log sequence number (LSN) associated with the commit transaction for the change. All changes committed in the same transaction share the same commit LSN. For example, if a delete operation on the source table removes two rows, the change table will contain two rows, each with the same __$start_lsn value.



__$end_lsn



binary(10)



Identified for informational purposes only. Not supported. Future compatibility is not guaranteed. In SQL Server 2008, this column is always NULL.



__$seqval



binary(10)



Sequence value used to order the row changes within a transaction.



__$operation



int



Identifies the data manipulation language (DML) operation associated with the change. Can be one of the following:
1 = delete
2 = insert
3 = update (old values) Column data has row values before executing the update statement.
4 = update (new values)


Column data has row values after executing the update statement.



__$update_mask



varbinary(128)



A bit mask based upon the column ordinals of the change table identifying those columns that changed.



<captured source table columns>



varies



The remaining columns in the change table are the columns from the source table that were identified as captured columns when the capture instance was created. If no columns were specified in the captured column list, all columns in the source table are included in this table.



The additional objects can be seen in SQL Server Management Studio under System Tables of the SAP database:



You can use the two functions to show the changes on the table. The function fn_cdc_get_ all _changes_<schema>_<table name> returns one row for every change on a table:


DECLARE @begin_time datetime;


DECLARE @end_time datetime:


DECLARE @begin_lsn binary(10);


DECLARE @end_lsn binary(10);


SET @begin_time = '2010-03-01 12:00:00.000';


SET @end_time = '2010-03-10 12:00:00.000';


-- Map the dates


SELECT @begin_lsn = sys.fn_cdc_map_time_to_lsn ('smallest greater than', @begin_time);


SELECT @end_lsn = sys.fn_cdc_map_time_to_lsn ('largest less than or equal', @end_time);


SELECT __$start_lsn, __$seqval, __$operation, __$update_mask,PROGNAME, R3STATE, TYPE FROM cdc.fn_cdc_get_all_changes_pax_REPOSRC( @begin_lsn, @end_lsn, 'all');


GO




Above you can see the changes of the column TYPE in the table REPOSRC from space to ‘A’ to ‘B’.


The function fn_cdc_get_ net _changes_<schema>_<table name> shows only the very last version of the row:



With this information you will be able to manually revert or replay the changes against data in a table. For long term auditing or monitoring purposes, it is


essential, that the data is moved outside the CDC monitoring tables (e.g. pax_REPOSRC_CT), because the data is kept in those tables for a short period of


time only.


The data in the CDC system tables is automatically purged by an SQL Agent job ( cdc.<DB Name>_Cleanup, e.g. cdc.PAX_cleanup) every night at 2:00 am.


In the default configuration the retention period is 4320 minutes (3 days). Means, only changes younger than 3 days will be available in the cdc monitoring


tables.  However one cleanup run will only delete up to 5000 entries per table. You can view this setting in msdb.dbo.cdc_job by running


SELECT retention, threshold, * FROM msdb.dbo.cdc_jobs WHERE job_type = 'cleanup'

Deleting 5000 rows in one cleanup might not be good enough to keep the volume of the CDC tables in check. Therefore if CDC tables grow day after day,


you might want to change these settings. To switch off CDC completely for a given table, you have to run the sp_cdc_disable_table procedure for the


created capture instance:


EXECUTE sys.sp_cdc_disable_table @source_schema = N'pax', @source_name = N'REPOSRC', @capture_instance = N'pax_REPOSRC'
GO

To de-activate CDC for an entire database you have to use the sp_cdc_disable_db procedure.


EXEC sp_cdc_disable_db
GO

This will remove all created objects in the cdc schema within the database.


Since the CDC functionality is based on the SQL Server Replication Log Sniffing Framework, you have to set the configuration option “max text repl size” to


its maximum of 2147483647, otherwise you will get truncation errors for tables with blob fields(e.g. REPOSRC).


The analysis and storage of the collected data has to be done outside of the SAP system. CDC can be used to get historical data about all changes on critical


tables within the system. In contradiction to other data monitoring solutions, CDC offers you the ability to get and store the information about the changes,


not only about the old and new values of columns.


Some useful Microsoft Knowledgebase articles for CDC:


FIX: A backup operation on a SQL Server 2008 database fails if you enable change tracking on th...


FIX: You cannot disable the CDC feature if you drop the cdc.change_tables CDC system table in S...


MSDN Change data capture

%3CLINGO-SUB%20id%3D%22lingo-sub-366955%22%20slang%3D%22en-US%22%3ESQL%20Server%20Change%20Data%20Capture%20with%20SAP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-366955%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Apr%2001%2C%202010%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EHello%20I%20am%20pleased%20to%20introduce%20Clas%20Hortien%20as%20new%20contributor%20to%20this%20blog%20site.%20He%20is%20located%20in%20the%20SAP%20development%20facilities%20in%20Germany.%20For%20many%20years%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ehis%20focus%20is%20to%20support%20SAP%20customers%20running%20on%20SQL%20Server.%20Some%20of%20you%20might%20know%20him%20by%20his%20contributions%20to%20the%20SDN%20SQL%20Server%20forum.%20Clas%20will%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Estart%20a%20series%20of%20articles%20looking%20at%20new%20features%20of%20SQL%20Server%202008%20in%20conjunction%20with%20SAP.%20As%20a%20first%20feature%20we%20start%20with%20%E2%80%9CChange%20Data%20Capture%E2%80%9D%20and%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ehow%20it%20could%20be%20leveraged%20in%20combination%20with%20an%20SAP%20system.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EChange%20Data%20Capture%20(CDC)%20provides%20information%20about%20DML%20changes%20on%20a%20table%20and%20a%20database.%20By%20using%20change%20data%20capture%2C%20you%20eliminate%20expensive%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Etechniques%20such%20as%20user%20triggers%2C%20timestamp%20columns%2C%20and%20join%20queries%20in%20order%20to%20detect%20changes.%20Change%20Data%20Capture%20records%20modifications%20on%20tables%20on%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewhich%20CDC%20got%20enabled.%20The%20details%20of%20the%20changes%20are%20available%20in%20a%20normal%20relational%20table%20for%20selection.%20CDC%20only%20tracks%20the%20columns%20which%20got%20modified%20as%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewe%20see%20later%20on%20in%20this%20article.%20Change%20Data%20Capture%20functionality%20is%20available%20only%20in%20SQL%20Server%202008%20Enterprise%2C%20Developer%2C%20and%20Evaluation%20editions.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESo%20far%20SAP%20does%20not%20provide%20any%20GUI%20or%20interface%20to%20setup%20or%20control%20the%20CDC%20feature.%20Since%20Basis%20release%20720%2C%20the%20DBA%20cockpit%20provides%20some%20monitoring%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Efunctionality%2C%20mainly%20to%20check%20the%20status%20and%20to%20see%20which%20tables%20are%20monitored%20through%20CDC.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F87614i93D28426567B8CFC%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EYou%20can%20find%20this%20new%20screen%20in%20the%20NON-SAP%20Features%20section%20of%20the%20Configuration%20branch%20in%20the%20DBA%20Cockpit%20(see%20the%20screenshot).%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EWhen%20you%20plan%20on%20using%20CDC%2C%20you%20should%20consider%20the%20following%20limitations%20and%20impacts%3A%3C%2FP%3E%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EYou%20may%20not%20use%20CDC%2C%20when%20your%20SAP%20System%20ID%20(SID)%20is%20CDC%2C%20because%20the%20Change%20Data%20Capture%20feature%20will%20interfere%20massively%20with%20your%20SAP%20system.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ECDC%20will%20have%20an%20impact%20on%20CPU%20and%20space%20usage%20in%20your%20system.%20Especially%20the%20space%20usage%20can%20be%20tremendously%2C%20when%20you%20monitor%20multiple%20tables%20which%20a%20high%20change%20rate.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EPlease%20never%20ever%20try%20to%20monitor%20the%20SAP%20queuing%20tables%20like%20VBDATA%2C%20VBHDR%20and%20VBMOD%20as%20the%20amount%20of%20data%20is%20enormous%20and%20not%20useful%20anyway.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EDo%20not%20monitor%20the%20SAP%20RFC%20tables%20like%20ARFC*%2C%20QRFC*%20and%20TRFC*.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ENever%20monitor%20all%20tables%20of%20an%20SAP%20system%20simultaneous.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EBe%20extremely%20selective%20what%20table%20to%20capture%20changes%20on%20and%20keep%20the%20number%20of%20tables%20limited.%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%3CP%3ETo%20use%20CDC%20you%20have%20to%20manually%20enable%20it%20in%20a%20SQL%20Query%20Window%20with%20the%20following%20T-SQL%20commands%3A%3C%2FP%3E%3CBR%20%2F%3E%20USE%20PAX%20%3CBR%20%2F%3E%20EXEC%20sp_cdc_enable_db%20%E2%80%93%20enabling%20it%20on%20the%20DB%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20--%20start%20it%20for%20some%20tables%20%3CBR%20%2F%3E%20EXEC%20sp_cdc_enable_table%20'pax'%2C%20%3CBR%20%2F%3E%20'REPOSRC'%2C%20%40role_name%20%3D%20null%2C%20%40supports_net_changes%20%3D1%3B%20%3CBR%20%2F%3E%20EXEC%20sp_cdc_enable_table%20'pax'%2C%20%3CBR%20%2F%3E%20'SNAP'%2C%20%40role_name%20%3D%20null%2C%20%40supports_net_changes%20%3D1%3B%20%3CBR%20%2F%3E%20EXEC%20sp_cdc_enable_table%20'pax'%2C%20%3CBR%20%2F%3E%20'sap_tabstats'%2C%20%40role_name%20%3D%20null%2C%20%40supports_net_changes%20%3D1%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%3CP%3EThe%20first%20command%20(sp_cdc_enable_db)%20enables%20CDC%20for%20the%20current%20database.%20All%20the%20necessary%20structures%20will%20be%20created%20and%20the%20database%20gets%20prepared%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Efor%20the%20CDC%20usage.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIn%20the%20example%20we%20started%20the%20monitoring%20for%20three%20tables%20(SNAP%20%E2%80%93%20Short%20dumps%2C%20REPOSRC%20%E2%80%93%20SAP%20Report%20sources%2C%20sap_tabstats%20%E2%80%93%20DBA%20Cockpit%20history%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Edata).%20With%20the%20option%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F32703%22%20target%3D%22_blank%22%3E%40Support%3C%2FA%3E_net_changes%20an%20additional%20function%20gets%20created%2C%20which%20shows%20the%20net%20changes%20on%20the%20table.%20By%20setting%20the%20%40role_name%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eoption%20to%20null%20the%20security%20of%20the%20tables%20which%20contains%20the%20changes%20is%20not%20restricted.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EChange%20Data%20Capture%20will%20create%20a%20new%20schema%20called%20%E2%80%98cdc%E2%80%99%20in%20the%20SAP%20database%20(therefore%20never%20use%20CDC%20with%20a%20SAP%20system%20using%20the%20SID%20of%20CDC).%20At%20least%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ethree%20additional%20objects%20are%20created%20in%20the%20new%20cdc%20schema%20in%20the%20SAP%20database%20for%20each%20table%20which%20is%20in%20the%20scope%20of%20CDC%3A%3C%2FP%3E%3CBR%20%2F%3E%3CTABLE%3E%0A%20%20%20%3CTBODY%3E%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20Object%20name%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20Type%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20Example%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%20%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Efn_cdc_get_all_changes_%3CSCHEMA%3E_%3CTABLE%20name%3D%22%22%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%0A%20%20%20%20%3CTBODY%3E%3CTR%3E%3CTD%3E%3CBR%20%2F%3E%3CP%3Efunction%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Efn_cdc_get_all_changes_pax_SNAP%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%20%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Efn_cdc_get_net_changes_%3CSCHEMA%3E_%3CTABLE%20name%3D%22%22%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%0A%20%20%20%20%3CTBODY%3E%3CTR%3E%3CTD%3E%3CBR%20%2F%3E%3CP%3Efunction%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Efn_cdc_get_net_changes_pax_SNAP%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%20%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E%3CSCHEMA%3E_%3CTABLE%20name%3D%22%22%3E_CT%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%0A%20%20%20%20%3CTBODY%3E%3CTR%3E%3CTD%3E%3CBR%20%2F%3E%3CP%3Etable%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Epax_SNAP_CT%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%3C%2FTBODY%3E%3C%2FTABLE%3E%3CBR%20%2F%3E%3C%2FSCHEMA%3E%3C%2FP%3E%3CP%3EThe%20table%20%3CSCHEMA%3E_%3CTABLE_NAME%3E_CT%20contains%20the%20data%20of%20the%20changed%20rows.%20It%20is%20an%20exact%20copy%20of%20the%20table%20structure%20of%20the%20source%20table%20(e.g.%20SNAP)%2C%3C%2FTABLE_NAME%3E%3C%2FSCHEMA%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ewith%20some%20additional%20fields%20(__%24start_lsn%2C%20__%24seqval%2C%20__%24operation%2C%20__%24update_mask)%20at%20the%20beginning%20of%20the%20table.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EFrom%20SQL%20Server%20Books%20online%3A%3C%2FP%3E%3CBR%20%2F%3E%3CTABLE%3E%0A%20%20%20%3CTBODY%3E%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20Column%20name%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20Data%20type%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20Description%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%20%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E__%24start_lsn%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Ebinary(10)%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3ELog%20sequence%20number%20(LSN)%20associated%20with%20the%20commit%20transaction%20for%20the%20change.%20All%20changes%20committed%20in%20the%20same%20transaction%20share%20the%20same%20commit%20LSN.%20For%20example%2C%20if%20a%20delete%20operation%20on%20the%20source%20table%20removes%20two%20rows%2C%20the%20change%20table%20will%20contain%20two%20rows%2C%20each%20with%20the%20same%20__%24start_lsn%20value.%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%20%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E__%24end_lsn%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Ebinary(10)%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EIdentified%20for%20informational%20purposes%20only.%20Not%20supported.%20Future%20compatibility%20is%20not%20guaranteed.%20In%20SQL%20Server%202008%2C%20this%20column%20is%20always%20NULL.%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%20%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E__%24seqval%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Ebinary(10)%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3ESequence%20value%20used%20to%20order%20the%20row%20changes%20within%20a%20transaction.%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%20%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E__%24operation%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Eint%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EIdentifies%20the%20data%20manipulation%20language%20(DML)%20operation%20associated%20with%20the%20change.%20Can%20be%20one%20of%20the%20following%3A%20%3CBR%20%2F%3E%201%20%3D%20delete%20%3CBR%20%2F%3E%202%20%3D%20insert%20%3CBR%20%2F%3E%203%20%3D%20update%20(old%20values)%20Column%20data%20has%20row%20values%20before%20executing%20the%20update%20statement.%20%3CBR%20%2F%3E%204%20%3D%20update%20(new%20values)%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EColumn%20data%20has%20row%20values%20after%20executing%20the%20update%20statement.%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%20%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E__%24update_mask%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Evarbinary(128)%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EA%20bit%20mask%20based%20upon%20the%20column%20ordinals%20of%20the%20change%20table%20identifying%20those%20columns%20that%20changed.%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%20%3CTR%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E%3CCAPTURED%20source%3D%22%22%20table%3D%22%22%20columns%3D%22%22%3E%3C%2FCAPTURED%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3Evaries%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EThe%20remaining%20columns%20in%20the%20change%20table%20are%20the%20columns%20from%20the%20source%20table%20that%20were%20identified%20as%20captured%20columns%20when%20the%20capture%20instance%20was%20created.%20If%20no%20columns%20were%20specified%20in%20the%20captured%20column%20list%2C%20all%20columns%20in%20the%20source%20table%20are%20included%20in%20this%20table.%3C%2FP%3E%3CBR%20%2F%3E%3C%2FTD%3E%0A%20%20%20%3C%2FTR%3E%0A%20%20%3C%2FTBODY%3E%3C%2FTABLE%3E%3CBR%20%2F%3E%3CP%3EThe%20additional%20objects%20can%20be%20seen%20in%20SQL%20Server%20Management%20Studio%20under%20System%20Tables%20of%20the%20SAP%20database%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F87615iDD68BDB23330A309%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EYou%20can%20use%20the%20two%20functions%20to%20show%20the%20changes%20on%20the%20table.%20The%20function%20fn_cdc_get_%20%3CB%3E%20all%20%3C%2FB%3E%20_changes_%3CSCHEMA%3E_%3CTABLE%20name%3D%22%22%3E%20returns%20one%20row%20for%20every%20change%20on%20a%20table%3A%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3EDECLARE%20%3C%2FB%3E%20%3CB%3E%20%40begin_time%20datetime%3B%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3EDECLARE%20%3C%2FB%3E%20%3CB%3E%20%40end_time%20datetime%3A%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3EDECLARE%20%3C%2FB%3E%20%3CB%3E%20%40begin_lsn%20binary(10)%3B%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3EDECLARE%20%3C%2FB%3E%20%3CB%3E%20%40end_lsn%20binary(10)%3B%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3ESET%20%3C%2FB%3E%20%3CB%3E%20%40begin_time%20%3D%20'2010-03-01%2012%3A00%3A00.000'%3B%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3ESET%20%3C%2FB%3E%20%3CB%3E%20%40end_time%20%3D%20'2010-03-10%2012%3A00%3A00.000'%3B%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3E%20--%20Map%20the%20dates%20%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3ESELECT%20%3C%2FB%3E%20%3CB%3E%20%40begin_lsn%20%3D%20sys.fn_cdc_map_time_to_lsn%20('smallest%20greater%20than'%2C%20%40begin_time)%3B%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3ESELECT%20%3C%2FB%3E%20%3CB%3E%20%40end_lsn%20%3D%20sys.fn_cdc_map_time_to_lsn%20('largest%20less%20than%20or%20equal'%2C%20%40end_time)%3B%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3ESELECT%20%3C%2FB%3E%20%3CB%3E%20__%24start_lsn%2C%20__%24seqval%2C%20__%24operation%2C%20__%24update_mask%2CPROGNAME%2C%20R3STATE%2C%20TYPE%20FROM%20cdc.fn_cdc_get_all_changes_pax_REPOSRC(%20%40begin_lsn%2C%20%40end_lsn%2C%20'all')%3B%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3E%20GO%20%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CB%3E%20%3C%2FB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F87616i6B715BED5E5F9953%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EAbove%20you%20can%20see%20the%20changes%20of%20the%20column%20TYPE%20in%20the%20table%20REPOSRC%20from%20space%20to%20%E2%80%98A%E2%80%99%20to%20%E2%80%98B%E2%80%99.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20function%20fn_cdc_get_%20%3CB%3E%20net%20%3C%2FB%3E%20_changes_%3CSCHEMA%3E_%3CTABLE%20name%3D%22%22%3E%20shows%20only%20the%20very%20last%20version%20of%20the%20row%3A%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F87617i5045FD3471A7168D%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EWith%20this%20information%20you%20will%20be%20able%20to%20manually%20revert%20or%20replay%20the%20changes%20against%20data%20in%20a%20table.%20For%20long%20term%20auditing%20or%20monitoring%20purposes%2C%20it%20is%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eessential%2C%20that%20the%20data%20is%20moved%20outside%20the%20CDC%20monitoring%20tables%20(e.g.%20pax_REPOSRC_CT)%2C%20because%20the%20data%20is%20kept%20in%20those%20tables%20for%20a%20short%20period%20of%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Etime%20only.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20data%20in%20the%20CDC%20system%20tables%20is%20automatically%20purged%20by%20an%20SQL%20Agent%20job%20(%20cdc.%3CDB%20name%3D%22%22%3E_Cleanup%2C%20e.g.%20cdc.PAX_cleanup)%20every%20night%20at%202%3A00%20am.%3C%2FDB%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIn%20the%20default%20configuration%20the%20retention%20period%20is%204320%20minutes%20(3%20days).%20Means%2C%20only%20changes%20younger%20than%203%20days%20will%20be%20available%20in%20the%20cdc%20monitoring%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Etables.%26nbsp%3B%20However%20one%20cleanup%20run%20will%20only%20delete%20up%20to%205000%20entries%20per%20table.%20You%20can%20view%20this%20setting%20in%20msdb.dbo.cdc_job%20by%20running%3C%2FP%3E%3CBR%20%2F%3E%20SELECT%20retention%2C%20threshold%2C%20*%20FROM%20msdb.dbo.cdc_jobs%20WHERE%20job_type%20%3D%20'cleanup'%20%3CBR%20%2F%3E%3CP%3EDeleting%205000%20rows%20in%20one%20cleanup%20might%20not%20be%20good%20enough%20to%20keep%20the%20volume%20of%20the%20CDC%20tables%20in%20check.%20Therefore%20if%20CDC%20tables%20grow%20day%20after%20day%2C%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eyou%20might%20want%20to%20change%20these%20settings.%20To%20switch%20off%20CDC%20completely%20for%20a%20given%20table%2C%20you%20have%20to%20run%20the%20sp_cdc_disable_table%20procedure%20for%20the%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Ecreated%20capture%20instance%3A%3C%2FP%3E%3CBR%20%2F%3E%20EXECUTE%20sys.sp_cdc_disable_table%20%40source_schema%20%3D%20N'pax'%2C%20%40source_name%20%3D%20N'REPOSRC'%2C%20%40capture_instance%20%3D%20N'pax_REPOSRC'%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%3CP%3ETo%20de-activate%20CDC%20for%20an%20entire%20database%20you%20have%20to%20use%20the%20sp_cdc_disable_db%20procedure.%3C%2FP%3E%3CBR%20%2F%3E%20EXEC%20sp_cdc_disable_db%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%3CP%3EThis%20will%20remove%20all%20created%20objects%20in%20the%20cdc%20schema%20within%20the%20database.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESince%20the%20CDC%20functionality%20is%20based%20on%20the%20SQL%20Server%20Replication%20Log%20Sniffing%20Framework%2C%20you%20have%20to%20set%20the%20configuration%20option%20%E2%80%9Cmax%20text%20repl%20size%E2%80%9D%20to%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eits%20maximum%20of%202147483647%2C%20otherwise%20you%20will%20get%20truncation%20errors%20for%20tables%20with%20blob%20fields(e.g.%20REPOSRC).%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20analysis%20and%20storage%20of%20the%20collected%20data%20has%20to%20be%20done%20outside%20of%20the%20SAP%20system.%20CDC%20can%20be%20used%20to%20get%20historical%20data%20about%20all%20changes%20on%20critical%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Etables%20within%20the%20system.%20In%20contradiction%20to%20other%20data%20monitoring%20solutions%2C%20CDC%20offers%20you%20the%20ability%20to%20get%20and%20store%20the%20information%20about%20the%20changes%2C%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Enot%20only%20about%20the%20old%20and%20new%20values%20of%20columns.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESome%20useful%20Microsoft%20Knowledgebase%20articles%20for%20CDC%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F978839%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20FIX%3A%20A%20backup%20operation%20on%20a%20SQL%20Server%202008%20database%20fails%20if%20you%20enable%20change%20tracking%20on%20this%20database%20%3C%2FA%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F966306%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20FIX%3A%20You%20cannot%20disable%20the%20CDC%20feature%20if%20you%20drop%20the%20cdc.change_tables%20CDC%20system%20table%20in%20SQL%20Server%202008%20%3C%2FA%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fbb522489.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20MSDN%20Change%20data%20capture%20%3C%2FA%3E%3C%2FP%3E%0A%20%0A%3CLINGO-TEASER%20id%3D%22lingo-teaser-366955%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Apr%2001%2C%202010%20Hello%20I%20am%20pleased%20to%20introduce%20Clas%20Hortien%20as%20new%20contributor%20to%20this%20blog%20site.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-366955%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdministration%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FTABLE%3E%3C%2FSCHEMA%3E%3C%2FP%3E%3C%2FTABLE%3E%3C%2FSCHEMA%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FSCHEMA%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FSCHEMA%3E%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FLINGO-BODY%3E
Version history
Last update:
‎Mar 13 2019 08:30 AM
Updated by: