Skip to content

Repository files navigation

CDCforOracle

SQL CDC for Oracle practice

Prepare-SQL-Server.sql

This SQL script is designed to prepare a SQL Server for Change Data Capture (CDC) by creating the necessary database objects, triggers, and stored procedures. The script begins by ensuring that the MSXDBCDC database exists, creating it if it does not. It then switches to using this database for subsequent operations.

The script creates three tables within the MSXDBCDC database: xdbcdc_databases, xdbcdc_services, and xdbcdc_trace. Each table is defined with specific columns and constraints. For example, xdbcdc_databases includes columns for the database name, configuration version, CDC service name, and an enabled flag, with a primary key constraint on the name column.

A trigger named tr_after_ui_dbo_xdbcdc_databases is created on the xdbcdc_databases table to update the config_version column whenever a row is inserted or updated. This ensures that the configuration version is always current.

The script also defines several stored procedures to manage the CDC setup:

  1. xdbcdc_enable_db: This procedure enables CDC for a specified database by creating necessary tables and triggers within the database and marking the database as enabled in the xdbcdc_databases table.
  2. xdbcdc_disable_db: This procedure disables CDC for a specified database by removing its entry from the xdbcdc_databases table.
  3. xdbcdc_reset_db: This procedure resets the CDC state for a specified database by truncating all CDC-related tables and resetting the start LSN (Log Sequence Number).
  4. xdbcdc_add_service: This procedure adds a new CDC service to the xdbcdc_services table or increments the reference count if the service already exists.
  5. xdbcdc_remove_service: This procedure decrements the reference count for a CDC service and removes it if the count reaches zero.
  6. xdbcdc_start: This procedure enables CDC for a specified database by setting the enabled flag to 1 in the xdbcdc_databases table.
  7. xdbcdc_stop: This procedure disables CDC for a specified database by setting the enabled flag to 0 in the xdbcdc_databases table.
  8. xdbcdc_update_config_version: This procedure updates the config_version column for a specified database to the current UTC date and time.

Overall, this script sets up the infrastructure needed for CDC on a SQL Server, allowing for the tracking and capturing of data changes in specified databases.

About

SQL CDC for Oracle practice

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages