我们是五月的花海 , 用青春拥抱时代 |

兴想事成

园龄:12年10个月粉丝:25关注:97

数据仓库之启用cdc

 

准备工作: 先将sqlservere 代理服务启动

 

复制代码
USE [MyDB];
GO
EXECUTE sys.sp_cdc_enable_db; --启用数据库对CDC的支持
GO

 -- 设置别名 @capture_instance = N'AAAA', 生成你的cdc捕获表为 cdc.AAAA_CT , 如果不设置@capture_instance,表名为 cdc.dbo_AAAA_CT

EXEC sys.sp_cdc_enable_table 'dbo', 
'tab_AAAA', @role_name = NULL,@capture_instance = N'AAAA', @supports_net_changes =0; --启用某个表对CDC的支持
GO
复制代码

 

 

关闭 某个 cdc捕获 

EXEC sys.sp_cdc_disable_table 'dbo', 'tab_AAAA','All'

 

 

 如果只只捕获一部分字段

EXEC sys.sp_cdc_enable_table 'opr_', 
'tab_BBBB', @role_name = NULL, @supports_net_changes =0,@capture_instance = N'BBBB',
@captured_column_list ='a,b,c,d,timeflag'

--启用某个表对CDC的支持 GO

 

 

对整个库进行cdc关闭

EXEC sys.sp_cdc_disable_db

 

 

2.cdc启用以后,可以在系统表中看到有一个对应表 [cdc].[BBBB_CT]

编写指定的时间查询, 以查询对应时间段的数据

 

复制代码
create PROC GetCDCResult
(@begin_time DATETIME,@end_time DATETIME,@cdcTableName varchar(100))
AS
DECLARE @from_lsn binary(10), @to_lsn binary(10);
SELECT @from_lsn = sys.fn_cdc_map_time_to_lsn('smallest greater than or equal', @begin_time);
SELECT @to_lsn = sys.fn_cdc_map_time_to_lsn('largest less than or equal', @end_time);

declare @sqlStr nvarchar(2000)
set @sqlStr = N'SELECT * FROM [cdc].['+@cdcTableName+'] WHERE __$start_lsn BETWEEN @from_lsn AND @to_lsn';
exec sp_executesql @sqlStr,N'@from_lsn binary(10),@to_lsn binary(10)',@from_lsn,@to_lsn ;

go
复制代码

 

 

--调用该存储过程
EXEC GetCDCResult '2001-01-1','2020-01-01','BBBB_CT'

 

关于 operation  1删除; 2新增; 3修改之前;4修改之后

 

cdc的信息是从数据库日志里面读取的, 获取的数据稍微延迟了一下.

 

posted @   兴想事成  阅读(1399)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 Good-bye My Loneliness ZARD
  2. 2 Say OK Vanessa Hudgens
  3. 3 All The Love In The World The Corrs
  4. 4 Adesso E Fortuna ~炎と永遠~ 加藤いづみ
Say OK - Vanessa Hudgens
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : BIRGISSON, ARNTHOR/KOTECHA, SAVAN

作曲 : Savan Kotecha/Arnthor Birgisson

Vanessa Hudgens - Say OK

Album: V

You are fine

You are fine

You are fine

You are fine

You are sweet

But I'm still a bit naive with my heart

When you're close I don't breathe

I can't find the words to speak

I feel sparks

But I don't wanna be into you

If you are not looking for true love, oh oh

No I don't wanna start seeing you

If I can't be your only one

So tell me when it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

When you call I don't know

If I should pick up the phone every time

I'm not like all my friends

Who keep calling up the boys, I'm so shy

But I don't wanna be into you

If you don't treat me the right way

See I can only start seeing you

If you can make my heart feel safe (feel safe)

When it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away, don't run away)

Let me know if it's gonna be you

Boy, you've got some things to prove

Let me know that you'll keep me safe

I don't want you to run away so

Let me know that you'll call on time

Let me know that you won't be shy

Will you wipe my tears away

Will you hold me closer

When it's not alright

When it's not ok

Will you try to make me feel better

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

(Don't run away, don't run away)

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

Will you say OK

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

You are fine

You are fine