Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

sys.fn_cdc_get_max_lsn (Transact-SQL)


Applies To: SQL Server 2014, SQL Server 2016 Preview

Returns the maximum log sequence number (LSN) from the start_lsn column in the cdc.lsn_time_mapping system table. You can use this function to return the high endpoint of the change data capture timeline for any capture instance.

Applies to: SQL Server (SQL Server 2008 through current version).

Topic link icon Transact-SQL Syntax Conventions

sys.fn_cdc_get_max_lsn ()


This function returns the maximum LSN in the start_lsn column of the cdc.lsn_time_mapping table. As such, it is the last LSN processed by the capture process when changes are propagated to the database change tables. It serves as the high endpoint for the all timelines that are associated with capture instances defined for the database.

The function is typically used to obtain an appropriate high endpoint for a query interval.

Requires membership in the public database role.

The following example returns the maximum LSN for all capture instances in the AdventureWorks2012 database.

USE AdventureWorks2012;
SELECT sys.fn_cdc_get_max_lsn()AS max_lsn;

The following example uses the maximum LSN returned by sys.fn_cdc_get_max_lsn to set the high endpoint for a query range for the capture instance HumanResources_Employee.

USE AdventureWorks2012;
DECLARE @from_lsn binary(10), @to_lsn binary(10);
SET @from_lsn = sys.fn_cdc_get_min_lsn(N'HumanResources_Employee');
SET @to_lsn = sys.fn_cdc_get_max_lsn();
SELECT * FROM cdc.fn_cdc_get_all_changes_HumanResources_Employee(@from_lsn, @to_lsn, 'all');
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft