sys.fn_all_changes_<capture_instance> (Transact-SQL)
Wrappers for the all changes query functions. The scripts that are required to create these functions are generated by the sys.sp_cdc_generate_wrapper_function stored procedure.
Column name | Column type | Description |
|---|---|---|
__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. |
__CDC_SEQVAL | binary(10) | Sequence value that is used to order the row changes in a transaction. |
<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. |
__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: row_filter_option = 'all' 'D' - delete operation 'I' - insert operation 'UN' - update operation new values row_filter_option = 'all update old' 'D' - delete operation 'I' - insert operation 'UN' - update operation new values 'UO' - update operation old values |
<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. |
The fn_all_changes_<capture_instance> function serves as a wrapper for the cdc.fn_cdc_get_all_changes_<capture_instance> query function. The sys.sp_cdc_generate_wrapper stored procedure is used to generate the script to create the wrapper.
Wrapper functions are not created automatically. There are two things you must do to create wrapper functions:
Run the stored procedure to generate the script to create the wrapper.
Execute the script to actually create the wrapper function.
Wrapper functions enable users to systematically query for changes that occurred within an interval bounded by datetime values instead of by LSN values. The wrapper functions perform all the required conversions between the provided datetime values and the LSN values needed internally as arguments to the query functions. When the wrapper functions are used serially to process a stream of change data, they ensure that no data is lost or repeated provided that the following convention is followed: the @end_time value of the interval associated with one call is supplied as the @start_time value for the interval associated with the subsequent call.
By using the @closed_high_end_point parameter when you create the script, you can generate wrappers to support either a closed upper bound or an open upper bound on the specified query window. That is, you can decide whether entries that have a commit time equal to the upper bound of the extraction interval are to be included in the interval. By default, the upper bound is included.
The result set that is returned by the all changes wrapper function returns the __$start_lsn and __$seqval columns of the change table as columns __CDC_STARTLSN and __CDC_SEQVAL, respectively. It follows these with only those tracked columns that appeared in the @column_list parameter when the wrapper was generated. If @column_list is NULL, all tracked source columns are returned. The source columns are followed by an operation column, __CDC_OPERATION, which is a one- or two-character column that identifies the operation.
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.
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 Using SQL Server Management Studio Templates.
