April 25, 2012

sp_help_log_shipping_secondary_database (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_help_log_shipping_secondary_database(nvarchar @secondary_database
, uniqueidentifier @secondary_id)

MetaData:

 create procedure sys.sp_help_log_shipping_secondary_database   
(
@secondary_database sysname = NULL
,@secondary_id uniqueidentifier = NULL
)
as
begin
set nocount on
declare @retcode int

--
-- security check
--
exec @retcode = sys.sp_MSlogshippingsysadmincheck
if (@retcode != 0 or @@error != 0)
return 1
--
-- must be invoked from master db
--
if (db_name() != N'master')
begin
raiserror(5001, 16,-1)
return 1
end
--
-- validate input
--
if (@secondary_database is null and @secondary_id is null)
begin
raiserror(14524, 16, 1, N'@secondary_database', N'@secondary_id')
return 1
end
--
-- do the resultset join
--
select
s.secondary_id
,s.primary_server
,s.primary_database
,s.backup_source_directory
,s.backup_destination_directory
,s.file_retention_period
,s.copy_job_id
,s.restore_job_id
,'monitor_server' = case when (s.user_specified_monitor = 1) then s.monitor_server else cast(NULL as sysname) end
,'monitor_server_security_mode' = case when (s.user_specified_monitor = 1) then s.monitor_server_security_mode else cast(NULL as bit) end
,sd.secondary_database
,sd.restore_delay
,sd.restore_all
,sd.restore_mode
,sd.disconnect_users
,sd.block_size
,sd.buffer_count
,sd.max_transfer_size
,sm.restore_threshold
,sm.threshold_alert
,sm.threshold_alert_enabled
,sm.last_copied_file
,sm.last_copied_date
,sm.last_copied_date_utc
,sm.last_restored_file
,sm.last_restored_date
,sm.last_restored_date_utc
,sm.history_retention_period
,sm.last_restored_latency
from ((msdb.dbo.log_shipping_secondary as s join msdb.dbo.log_shipping_secondary_databases as sd
on s.secondary_id = sd.secondary_id)
join msdb.dbo.log_shipping_monitor_secondary as sm
on sd.secondary_id = sm.secondary_id
and sd.secondary_database = sm.secondary_database
and s.primary_server = sm.primary_server
and s.primary_database = sm.primary_database)
where (@secondary_database is null or sd.secondary_database = @secondary_database)
and (@secondary_id is null or s.secondary_id = @secondary_id)
--
-- all done
--
return 0
end

No comments:

Post a Comment

Total Pageviews