April 16, 2012

sp_cdc_dbsnapshotLSN (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_cdc_dbsnapshotLSN(nvarchar @db_snapshot)

MetaData:

   
create procedure [sys].[sp_cdc_dbsnapshotLSN]
(
@db_snapshot sysname,
@lastLSN binary(10) = null output,
@lastLSNstr varchar(40) = null output
)
as
begin
declare @command nvarchar(max), @str nvarchar(1000), @begin_char int
,@lsn binary(10), @lsn_str nvarchar(40), @db_snapshot_quoted nvarchar(1000)

declare @temp table(parentObject nvarchar(255),Object nvarchar(255),field nvarchar(255),value nvarchar(255))

-- Verify that the database snapshot exists
if not exists (
select name from sys.databases
where name = @db_snapshot
and source_database_id is not null)
begin
select @db_snapshot_quoted = quotename(@db_snapshot)
raiserror(22862, 16, -1, @db_snapshot_quoted)
return 1
end

set @lsn = 0x00
set @lsn_str = null
set @command = N'dbcc dbtable(' + quotename(@db_snapshot) + N') with tableresults, no_infomsgs'

insert into @temp exec( @command )
select @str = value from @temp where field = N'm_splitPoint';

if @str is not null
begin
select @begin_char = CHARINDEX('(', @str)
select @lsn_str = SUBSTRING(@str, @begin_char + 3, 8) + SUBSTRING(@str, @begin_char + 12, 8)
+ SUBSTRING(@str, @begin_char + 21, 4)
select @lsn = sys.fn_cdc_hexstrtobin(@lsn_str)
end

set @lastLSN = @lsn
set @lastLSNstr = @lsn_str

return 0
end

No comments:

Post a Comment

Total Pageviews