近期根据公司规划,需要将以前SQLSERVER数据库部分表中数据增量取到ORACLE数据库中,决定使用sqlserver2008中新增的CDC(变更数据捕获)功能来实现。具体操作步
近期根据公司规划,需要将以前SQLSERVER数据库部分表中数据增量取到ORACLE数据库中,决定使用sqlserver2008中新增的CDC(变更数据捕获)功能来实现。
具体操作步骤如下:
1. 查看指定数据库有没有启用CDC功能
SELECT is_cdc_enabled FROM sys.databases WHERE name = 'jointown'
2. 在数据库级启用CDC功能
EXEC sys.sp_cdc_enable_db
3. 创建一个测试表
create table t1 (id int,name varchar(20));
4. 在测试表上启用CDC
EXEC sys.sp_cdc_enable_table
@source_schema = 'dbo',
@source_name = 't1',
@role_name = NULL,
@capture_instance = NULL,
@supports_net_changes = 1,
@index_name = NULL,
@captured_column_list = NULL,
@filegroup_name = default
执行时报错,美国服务器,需要在表中设置主键或唯一键
再次启用成功:
5. 提醒:若要CDC能正常工作,虚拟主机,除了以上配置外,需要开启agent服务!
6. 检查指定表上CDC是否已经启用
SELECT is_tracked_by_cdc FROM sys.tables WHERE name = 't1' and schema_id = SCHEMA_ID('dbo')
7. 此时查看变更数据捕获表,根据之前建的表t1,对应的存放变更数据的表为cdc.dbo_t1_ct,表中暂无任何数据
8. 在t1表中分别插入与更改一条数据后再查看
insert into t1 values (1,'a');
select * from cdc.dbo_t1_ct
在跟踪表中可以看到源表数据插入已被捕获,相比原表而言,网站空间,cdc表中新增了五列,一般我们额外需要关注的主要是__$start_lsn与__$operation 这两列,前一列存放此操作对应的数据库lsn号,后一列存放当前操作类型,以下为__$operation列对应操作类型:
1=delete,
2=insert,
3=update(旧值),
4=update(新值)。
通过以上操作可以看到,配置CDC过程本身来说是比较简单的,可以很方便的在对应的CDC表中跟踪到原表所做的数据操作,有了这些跟踪的数据后相应的开发人员就可以很方便的将sqlserver中源库和表中的数据捕获后同步到对应的其它库中,相比原来2005的触发器的方式,在效率和方便性上有了极大的提高。
本文出自 “天知道的技术博客” 博客,请务必保留此出处

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

TostorestringsefficientlyinMySQL,choosetherightdatatypebasedonyourneeds:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseTEXTforlong-formtextcontent.4)UseBLOBforbinarydatalikeimages.Considerstorageov

When selecting MySQL's BLOB and TEXT data types, BLOB is suitable for storing binary data, and TEXT is suitable for storing text data. 1) BLOB is suitable for binary data such as pictures and audio, 2) TEXT is suitable for text data such as articles and comments. When choosing, data properties and performance optimization must be considered.

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQLstringdatatypesshouldbechosenbasedondatacharacteristicsandusecases:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseBINARYorVARBINARYforbinarydatalikecryptographickeys.4)UseBLOBorTEXTforlargeuns


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
