Skip to content

Commit 02a3e4f

Browse files
authored
Merge pull request #19979 from WilliamDAssafMSFT/20210809-CDC-wrapper-functions
20210809 improve documentation for cdc functions and error 313
2 parents dc1b893 + 1d1821d commit 02a3e4f

6 files changed

Lines changed: 53 additions & 42 deletions

docs/relational-databases/system-functions/cdc-fn-cdc-get-all-changes-capture-instance-transact-sql.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: "cdc.fn_cdc_get_all_changes_<capture_instance> (Transact-SQL)"
33
title: "cdc.fn_cdc_get_all_changes_<capture_instance> (Transact-SQL)"
44
ms.custom: ""
5-
ms.date: "07/26/2021"
5+
ms.date: "08/12/2021"
66
ms.prod: sql
77
ms.prod_service: "database-engine"
88
ms.reviewer: ""
@@ -78,7 +78,7 @@ cdc.fn_cdc_get_all_changes_capture_instance ( from_lsn , to_lsn , '<row_filter_o
7878

7979
Columns of data type **image**, **text**, and **ntext** are always assigned a NULL value when **__$operation** = 1 or **__$operation** = 3. Columns of data type **varbinary(max)**, **varchar(max)**, or **nvarchar(max)** are assigned a NULL value when **__$operation** = 3 unless the column changed during the update. When **__$operation** = 1, these columns are assigned their value at the time of the delete. Computed columns that are included in a capture instance always have a value of NULL.
8080

81-
Error 313 is expected if LSN range supplied is not appropriate when calling `cdc.fn_cdc_get_all_changes_<capture_instance>` or `cdc.fn_cdc_get_net_changes_<capture_instance>`. If the value of either @start_time or @end_time parameter is beyond the time of lowest LSN or highest LSN, then execution of generated wrapper functions will return in error 313: `Msg 313, Level 16, State 3, Line 1 An insufficient number of arguments were supplied for the procedure or function`. This error should be handled by the developer.
81+
Error 313 is expected if LSN range supplied is not appropriate when calling `cdc.fn_cdc_get_all_changes_<capture_instance>` or `cdc.fn_cdc_get_net_changes_<capture_instance>`. If the `lsn_value` parameter is beyond the time of lowest LSN or highest LSN, then execution of these functions will return in error 313: `Msg 313, Level 16, State 3, Line 1 An insufficient number of arguments were supplied for the procedure or function`. This error should be handled by the developer.
8282

8383
## Examples
8484
Several [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] templates are available that show how to use the change data capture query functions. These templates are available on the **View** menu in [!INCLUDE[ssManStudio](../../includes/ssmanstudio-md.md)]. For more information, see [Template Explorer](../../ssms/template/template-explorer.md).
@@ -101,11 +101,11 @@ GO
101101
```
102102

103103
## See Also
104-
[cdc.fn_cdc_get_net_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-net-changes-capture-instance-transact-sql.md)
105-
[sys.fn_cdc_map_time_to_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-map-time-to-lsn-transact-sql.md)
106-
[sys.sp_cdc_get_ddl_history &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-get-ddl-history-transact-sql.md)
107-
[sys.sp_cdc_get_captured_columns &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-get-captured-columns-transact-sql.md)
108-
[sys.sp_cdc_help_change_data_capture &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-help-change-data-capture-transact-sql.md)
109-
[About Change Data Capture &#40;SQL Server&#41;](../../relational-databases/track-changes/about-change-data-capture-sql-server.md)
104+
- [cdc.fn_cdc_get_net_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-net-changes-capture-instance-transact-sql.md)
105+
- [sys.fn_cdc_map_time_to_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-map-time-to-lsn-transact-sql.md)
106+
- [sys.sp_cdc_get_ddl_history &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-get-ddl-history-transact-sql.md)
107+
- [sys.sp_cdc_get_captured_columns &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-get-captured-columns-transact-sql.md)
108+
- [sys.sp_cdc_help_change_data_capture &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-help-change-data-capture-transact-sql.md)
109+
- [About Change Data Capture &#40;SQL Server&#41;](../../relational-databases/track-changes/about-change-data-capture-sql-server.md)
110110

111111

docs/relational-databases/system-functions/cdc-fn-cdc-get-net-changes-capture-instance-transact-sql.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: "cdc.fn_cdc_get_net_changes_&lt;capture_instance&gt; (Transact-SQL)"
33
title: "cdc.fn_cdc_get_net_changes_&lt;capture_instance&gt; (Transact-SQL)"
44
ms.custom: ""
5-
ms.date: "07/26/2021"
5+
ms.date: "08/12/2021"
66
ms.prod: sql
77
ms.prod_service: "database-engine"
88
ms.reviewer: ""
@@ -87,7 +87,7 @@ cdc.fn_cdc_get_net_changes_capture_instance ( from_lsn , to_lsn , '<row_filter_o
8787

8888
Modifications on the unique identifier of a row will cause `fn_cdc_get_net_changes` to show the initial UPDATE command with a DELETE and then INSERT command instead. This behavior is necessary to track the key both before and after the change.
8989

90-
Error 313 is expected if LSN range supplied is not appropriate when calling `cdc.fn_cdc_get_all_changes_<capture_instance>` or `cdc.fn_cdc_get_net_changes_<capture_instance>`. If the value of either @start_time or @end_time parameter is beyond the time of lowest LSN or highest LSN, then execution of generated wrapper functions will return in error 313: `Msg 313, Level 16, State 3, Line 1 An insufficient number of arguments were supplied for the procedure or function`. This error should be handled by the developer.
90+
Error 313 is expected if LSN range supplied is not appropriate when calling `cdc.fn_cdc_get_all_changes_<capture_instance>` or `cdc.fn_cdc_get_net_changes_<capture_instance>`. If the `lsn_value` parameter is beyond the time of lowest LSN or highest LSN, then execution of these functions will return in error 313: `Msg 313, Level 16, State 3, Line 1 An insufficient number of arguments were supplied for the procedure or function`. This error should be handled by the developer.
9191

9292
## Examples
9393
The following example uses the function `cdc.fn_cdc_get_net_changes_HR_Department` to report the net changes made to the source table `HumanResources.Department` during a specific time interval.
@@ -122,10 +122,10 @@ SELECT * FROM cdc.fn_cdc_get_net_changes_HR_Department(@from_lsn, @to_lsn, 'all'
122122
```
123123

124124
## See Also
125-
[cdc.fn_cdc_get_all_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-all-changes-capture-instance-transact-sql.md)
126-
[sys.fn_cdc_map_time_to_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-map-time-to-lsn-transact-sql.md)
127-
[sys.sp_cdc_enable_table &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-enable-table-transact-sql.md)
128-
[sys.sp_cdc_help_change_data_capture &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-help-change-data-capture-transact-sql.md)
129-
[About Change Data Capture &#40;SQL Server&#41;](../../relational-databases/track-changes/about-change-data-capture-sql-server.md)
125+
- [cdc.fn_cdc_get_all_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-all-changes-capture-instance-transact-sql.md)
126+
- [sys.fn_cdc_map_time_to_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-map-time-to-lsn-transact-sql.md)
127+
- [sys.sp_cdc_enable_table &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-enable-table-transact-sql.md)
128+
- [sys.sp_cdc_help_change_data_capture &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-help-change-data-capture-transact-sql.md)
129+
- [About Change Data Capture &#40;SQL Server&#41;](../../relational-databases/track-changes/about-change-data-capture-sql-server.md)
130130

131131

docs/relational-databases/system-functions/sys-fn-all-changes-capture-instance-transact-sql.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: "sys.fn_all_changes_&lt;capture_instance&gt; (Transact-SQL)"
33
title: "sys.fn_all_changes_&lt;capture_instance&gt; (Transact-SQL)"
44
ms.custom: ""
5-
ms.date: "07/26/2021"
5+
ms.date: "08/12/2021"
66
ms.prod: sql
77
ms.prod_service: "database-engine"
88
ms.reviewer: ""
@@ -85,7 +85,7 @@ fn_all_changes_<capture_instance> ('start_time' ,'end_time', '<row_filter_option
8585
|-----------------|-----------------|-----------------|
8686
|__CDC_STARTLSN|**binary(10)**|The commit LSN of the transaction that is associated with the change. All changes that are committed in the same transaction share the same commit LSN.|
8787
|__CDC_SEQVAL|**binary(10)**|Sequence value that is used to order the row changes in a transaction.|
88-
|\<columns from @column_list>|**varies**|The columns that are identified in the *column_list* argument to sp_cdc_generate_wrapper_function when it is called to generate the script that creates the wrapper function.|
88+
|\<columns from @column_list>|**varies**|The columns that are identified in the *column_list* argument to `sp_cdc_generate_wrapper_function` when it is called to generate the script that creates the wrapper function.|
8989
|__CDC_OPERATION|**nvarchar(2)**|Operation code that indicates the operation that is required to apply the row to the target environment. It will vary based on the value of the argument *row_filter_option* supplied in the call:<br /><br /> *row_filter_option* = 'all'<br /><br /> 'D' - delete operation<br /><br /> 'I' - insert operation<br /><br /> 'UN' - update operation new values<br /><br /> *row_filter_option* = 'all update old'<br /><br /> 'D' - delete operation<br /><br /> 'I' - insert operation<br /><br /> 'UN' - update operation new values<br /><br /> 'UO' - update operation old values|
9090
|\<columns from @update_flag_list>|**bit**|A bit flag is named by appending _uflag to the column name. The flag is always set to NULL when \__CDC_OPERATION is 'D', 'I', of 'UO'. When \__CDC_OPERATION is 'UN', it is set to 1 if the update produced a change to the corresponding column. Otherwise, 0.|
9191

@@ -106,10 +106,14 @@ fn_all_changes_<capture_instance> ('start_time' ,'end_time', '<row_filter_option
106106

107107
Bit flags are then appended to the result set for each column that is identified in the @update_flag_list parameter. For the **all changes** wrapper, the bit flags will always be NULL if __CDC_OPERATION is 'D', 'I', or 'UO'. If \__CDC_OPERATION is 'UN', the flag will be set to 1 or 0, depending on whether the update operation caused a change to the column.
108108

109-
The change data capture configuration template 'Instantiate CDC Wrapper TVFs for Schema' shows how to use the sp_cdc_generate_wrapper_function stored procedure to obtain CREATE scripts for all of the wrapper functions for a schema's defined query functions. The template then creates those scripts. For more information about templates, see [Template Explorer](../../ssms/template/template-explorer.md).
109+
The change data capture configuration template 'Instantiate CDC Wrapper TVFs for Schema' shows how to use the `sp_cdc_generate_wrapper_function` stored procedure to obtain CREATE scripts for all of the wrapper functions for a schema's defined query functions. The template then creates those scripts. For more information about templates, see [Template Explorer](../../ssms/template/template-explorer.md).
110+
111+
The wrapper functions `sys.fn_all_changes_<capture_instance>` and `sys.fn_net_changes_<capture_instance>` are dependent on the system functions `cdc.fn_cdc_get_all_changes_<capture_instance>` and `cdc.fn_cdc_get_net_changes_<capture_instance>`. Error 313 is expected if LSN range supplied is not appropriate when calling `cdc.fn_cdc_get_all_changes_<capture_instance>` or `cdc.fn_cdc_get_net_changes_<capture_instance>`. If the `lsn_value` parameter is beyond the time of lowest LSN or highest LSN, then execution of these functions will return in error 313: `Msg 313, Level 16, State 3, Line 1 An insufficient number of arguments were supplied for the procedure or function`. This error should be handled by the developer.
110112

111113
## See Also
112-
[sys.sp_cdc_generate_wrapper_function &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-generate-wrapper-function-transact-sql.md)
113-
[cdc.fn_cdc_get_all_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-all-changes-capture-instance-transact-sql.md)
114+
115+
- [sys.fn_net_changes_<capture_instance>](sys-fn-net-changes-capture-instance-transact-sql.md)
116+
- [sys.sp_cdc_generate_wrapper_function &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sys-sp-cdc-generate-wrapper-function-transact-sql.md)
117+
- [cdc.fn_cdc_get_all_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-all-changes-capture-instance-transact-sql.md)
114118

115119

docs/relational-databases/system-functions/sys-fn-cdc-decrement-lsn-transact-sql.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: "sys.fn_cdc_decrement_lsn (Transact-SQL)"
33
title: "sys.fn_cdc_decrement_lsn (Transact-SQL)"
44
ms.custom: ""
5-
ms.date: "07/26/2021"
5+
ms.date: "08/12/2021"
66
ms.prod: sql
77
ms.prod_service: "database-engine"
88
ms.reviewer: ""
@@ -45,7 +45,7 @@ sys.fn_cdc_decrement_lsn ( lsn_value )
4545

4646
## Remarks
4747
The LSN returned by the function is always less than the specified value, and no LSN values can exist between the two values.
48-
48+
4949
## Permissions
5050
Requires membership in the **public** database role.
5151

@@ -60,13 +60,16 @@ SET @from_lsn = sys.fn_cdc_get_min_lsn('HumanResources_Employee');
6060
SET @to_lsn = sys.fn_cdc_decrement_lsn(sys.fn_cdc_get_max_lsn());
6161
SELECT * FROM cdc.fn_cdc_get_all_changes_HumanResources_Employee( @from_lsn, @to_lsn, 'all');
6262
GO
63-
```
63+
```
64+
65+
> [!NOTE]
66+
> Error 313 is expected if LSN range supplied is not appropriate when calling `cdc.fn_cdc_get_all_changes_<capture_instance>` or `cdc.fn_cdc_get_net_changes_<capture_instance>`. If the `lsn_value` parameter is beyond the time of lowest LSN or highest LSN, then execution of these functions will return in error 313: `Msg 313, Level 16, State 3, Line 1 An insufficient number of arguments were supplied for the procedure or function`. This error should be handled by the developer.
6467
6568
## See Also
66-
[sys.fn_cdc_increment_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-increment-lsn-transact-sql.md)
67-
[sys.fn_cdc_get_min_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-get-min-lsn-transact-sql.md)
68-
[sys.fn_cdc_get_max_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-get-max-lsn-transact-sql.md)
69-
[The Transaction Log &#40;SQL Server&#41;](../../relational-databases/logs/the-transaction-log-sql-server.md)
70-
[About Change Data Capture &#40;SQL Server&#41;](../../relational-databases/track-changes/about-change-data-capture-sql-server.md)
69+
- [sys.fn_cdc_increment_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-increment-lsn-transact-sql.md)
70+
- [sys.fn_cdc_get_min_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-get-min-lsn-transact-sql.md)
71+
- [sys.fn_cdc_get_max_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-get-max-lsn-transact-sql.md)
72+
- [The Transaction Log &#40;SQL Server&#41;](../../relational-databases/logs/the-transaction-log-sql-server.md)
73+
- [About Change Data Capture &#40;SQL Server&#41;](../../relational-databases/track-changes/about-change-data-capture-sql-server.md)
7174

7275

docs/relational-databases/system-functions/sys-fn-cdc-increment-lsn-transact-sql.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: "sys.fn_cdc_increment_lsn (Transact-SQL)"
33
title: "sys.fn_cdc_increment_lsn (Transact-SQL) | Microsoft Docs"
44
ms.custom: ""
5-
ms.date: "03/14/2017"
5+
ms.date: "08/12/2021"
66
ms.prod: sql
77
ms.prod_service: "database-engine"
88
ms.reviewer: ""
@@ -47,11 +47,9 @@ sys.fn_cdc_increment_lsn ( lsn_value )
4747
The LSN value returned by the function is always greater than the specified value, and no LSN values exist between the two values.
4848

4949
To systematically query a stream of change data over time, you can repeat the query function call periodically, each time specifying a new query interval to bound the changes returned in the query. To help insure that no data is lost, the upper bound for the previous query is often used to generate the lower bound for the subsequent query. Because the query interval is a closed interval, the new lower bound must be larger than the previous upper bound, but small enough to ensure no changes have LSN values that lie between this value and the old upper bound. The function `sys.fn_cdc_increment_lsn` is used to obtain this value.
50-
51-
Error 313 is expected if LSN range supplied is not appropriate when calling `cdc.fn_cdc_get_all_changes_<capture_instance>` or `cdc.fn_cdc_get_net_changes_<capture_instance>`. If the value of either @start_time or @end_time parameter is beyond the time of lowest LSN or highest LSN, then execution of generated wrapper functions will return in error 313: `Msg 313, Level 16, State 3, Line 1 An insufficient number of arguments were supplied for the procedure or function`. This error should be handled by the developer.
5250

5351
## Permissions
54-
Requires membership in the public database role.
52+
Requires membership in the **public** database role.
5553

5654
## Examples
5755
The following example uses `sys.fn_cdc_increment_lsn` to generate a new lower bound value for a change data capture query based on the upper bound saved from a previous query and saved in the variable `@save_to_lsn`.
@@ -67,12 +65,14 @@ SELECT * from cdc.fn_cdc_get_all_changes_HumanResources_Employee( @from_lsn, @to
6765
GO
6866
```
6967

68+
> [!NOTE]
69+
> Error 313 is expected if LSN range supplied is not appropriate when calling `cdc.fn_cdc_get_all_changes_<capture_instance>` or `cdc.fn_cdc_get_net_changes_<capture_instance>`. If the `lsn_value` parameter is beyond the time of lowest LSN or highest LSN, then execution of these functions will return in error 313: `Msg 313, Level 16, State 3, Line 1 An insufficient number of arguments were supplied for the procedure or function`. This error should be handled by the developer.
7070
7171
## See Also
72-
[sys.fn_cdc_decrement_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-decrement-lsn-transact-sql.md)
73-
[cdc.fn_cdc_get_all_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-all-changes-capture-instance-transact-sql.md)
74-
[cdc.fn_cdc_get_net_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-net-changes-capture-instance-transact-sql.md)
75-
[The Transaction Log &#40;SQL Server&#41;](../../relational-databases/logs/the-transaction-log-sql-server.md)
76-
[About Change Data Capture &#40;SQL Server&#41;](../../relational-databases/track-changes/about-change-data-capture-sql-server.md)
72+
- [sys.fn_cdc_decrement_lsn &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-cdc-decrement-lsn-transact-sql.md)
73+
- [cdc.fn_cdc_get_all_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-all-changes-capture-instance-transact-sql.md)
74+
- [cdc.fn_cdc_get_net_changes_&#60;capture_instance&#62; &#40;Transact-SQL&#41;](../../relational-databases/system-functions/cdc-fn-cdc-get-net-changes-capture-instance-transact-sql.md)
75+
- [The Transaction Log &#40;SQL Server&#41;](../../relational-databases/logs/the-transaction-log-sql-server.md)
76+
- [About Change Data Capture &#40;SQL Server&#41;](../../relational-databases/track-changes/about-change-data-capture-sql-server.md)
7777

7878

0 commit comments

Comments
 (0)