-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChangeDataCaptureFunction.sql
More file actions
63 lines (52 loc) · 1.75 KB
/
Copy pathChangeDataCaptureFunction.sql
File metadata and controls
63 lines (52 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
declare @rc int
exec @rc = sys.sp_cdc_enable_db
select @rc
-- new column added to sys.databases: is_cdc_enabled
select name, is_cdc_enabled from sys.databases
EXEC sys.sp_cdc_enable_db
GO
EXEC sys.sp_cdc_enable_table
@source_schema = N'dbo',
@source_name = N'customer2',
@role_name = 'CDCRole',
@supports_net_changes = 1
GO
select * from
create table dbo.customer2
(
id int identity not null
, name varchar(50) not null
, state varchar(2) not null
, constraint pk_customer2 primary key clustered (id)
)
exec sys.sp_cdc_enable_table
@source_schema = 'dbo',
@source_name = 'State' ,
@role_name = 'CDCRole',
@supports_net_changes = 1
select name, type, type_desc, is_tracked_by_cdc from sys.tables
insert customer2 values ('abc company', 'md')
insert customer2 values ('xyz company', 'de')
insert customer2 values ('xox company', 'va')
update customer2 set state = 'WV' where id = 3
delete from customer2 where id = 3
select * from customer2
declare @begin_lsn binary(10), @end_lsn binary(10)
-- get the first LSN for customer changes
select @begin_lsn = sys.fn_cdc_get_min_lsn('Masi_UserAccount')
-- get the last LSN for customer changes
select @end_lsn = sys.fn_cdc_get_max_lsn()
-- get net changes; group changes in the range by the pk
print @begin_lsn
print @end_lsn
update enterpriseservice.cdclsnlowerbound
set lsnlowerbound = @begin_lsn
where captureinstancename = 'Masi_UserAccount'
select * from cdc.fn_cdc_get_net_changes_Masi_UserRole(@begin_lsn, @end_lsn, 'all');
-- get individual changes in the range
select * from cdc.fn_cdc_get_all_changes_Masi_UserRole(
@begin_lsn, @end_lsn, 'all');
update dbo.[state]
set [description] = 'ZZ'
where name = 'west virginia'
select * from dberrorlog