May 24, 2012

sp_MSpeerapplyresponse (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_MSpeerapplyresponse(int @request_id
, nvarchar @originator
, nvarchar @originator_db
, nvarchar @response_srvr
, nvarchar @response_db)

MetaData:

 create procedure sys.sp_MSpeerapplyresponse  
(
@request_id int,
@originator sysname,
@originator_db sysname,
@response_srvr sysname,
@response_db sysname
)
as
begin
set nocount on

declare @retcode int

-- security check for subscriber
exec @retcode = sys.sp_MSreplcheck_subscribe
if @@error <> 0 or @retcode <> 0
begin
return 1
end

-- we will exit in either of these conditions since this means we
-- are not at the correct node and we should treat this as a noop
-- the conditions are as follows:
-- 1. Any of the user provided information is NULL
-- 2. We are not on the originator server
-- 3. The originator and reponse_srvr are the same
--
-- section 1
if @request_id is NULL
or @originator is NULL
or @originator_db is NULL
or @response_srvr is NULL
or @response_db is NULL
-- section 2
or UPPER(@originator) <> UPPER(publishingservername())
or @originator_db <> db_name()
-- section 3
or (UPPER(@originator) = UPPER(@response_srvr)
and @originator_db = @response_db)
begin
return 0
end

begin transaction tr_sp_MSpeerapplyresponse
save transaction tr_sp_MSpeerapplyresponse

update MSpeer_response
set received_date = getdate()
where request_id = @request_id
and peer = @response_srvr
and peer_db = @response_db
if @@error <> 0
begin
-- The procedure sys.sp_MSpeerapplyresponse failed to UPDATE the resource MSpeer_response Server error = 0.
raiserror (21499, 16, -1, 'sys.sp_MSpeerapplyresponse', 'UPDATE', 'MSpeer_response.', @@error)
goto FAILURE
end

commit transaction tr_sp_MSpeerapplyresponse

return 0
FAILURE:
rollback transaction tr_sp_MSpeerapplyresponse
commit transaction

return 1
end

sp_MSpeerconflictdetection_statuscollection_applyresponse (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_MSpeerconflictdetection_statuscollection_applyresponse(int @request_id
, nvarchar @peer_node
, nvarchar @peer_db
, int @peer_db_version
, bit @conflictdetection_enabled
, int @peer_originator_id
, int @peer_conflict_retention
, bit @peer_continue_onconflict
, nvarchar @peer_histids
, nvarchar @originator_node
, nvarchar @originator_db)

MetaData:

 create procedure sys.sp_MSpeerconflictdetection_statuscollection_applyresponse (  
@request_id int,
@peer_node sysname,
@peer_db sysname,
@peer_db_version int,
@conflictdetection_enabled bit,
@peer_originator_id int,
@peer_conflict_retention int,
@peer_continue_onconflict bit,
@peer_histids nvarchar(max), -- content of MSpeer_originatorid_history in xml format
@originator_node sysname,
@originator_db sysname
)
as
begin
-- security check - should be dbo or sysadmin
declare @retcode int
exec @retcode = sp_MSreplcheck_subscribe
if @@ERROR != 0 or @retcode != 0
return

if sys.fn_MSrepl_istranpublished(db_name(), 1) <> 1
return

if publishingservername() <> @originator_node or db_name() <> @originator_db
return

declare @publication sysname
select @publication = publication
from MSpeer_conflictdetectionconfigrequest
where id = @request_id

if @publication is NULL -- request does not exists
return;

begin tran
save tran tr_statuscollection_applyresp

update MSpeer_conflictdetectionconfigresponse
set peer_db_version = @peer_db_version,
conflictdetection_enabled = @conflictdetection_enabled,
originator_id = @peer_originator_id,
peer_conflict_retention = @peer_conflict_retention,
peer_continue_onconflict = @peer_continue_onconflict,
progress_phase = N'status collected',
modified_date = GETDATE()
where request_id = @request_id
and peer_node = @peer_node
and peer_db = @peer_db
and progress_phase = N'peer version collected'
if @@error <> 0
goto UNDO

-- incorporate historical originator IDs into MSpeer_originatorid_history
-- @peer_histids contains the root : /peer_histids
declare @DocHandle int
exec sp_xml_preparedocument @DocHandle OUTPUT, @peer_histids
if @@error <> 0
goto UNDO

insert MSpeer_originatorid_history (originator_publication, originator_id, originator_node, originator_db, originator_db_version, originator_version)
select @publication, originator_id, originator_node, originator_db, originator_db_version, originator_version
from ( select *
from OPENXML (@DocHandle, N'/peer_histids/histid', 1)
with (originator_id int, originator_node sysname, originator_db sysname, originator_db_version int, originator_version int)
) as A
where not exists (select * from MSpeer_originatorid_history
where originator_publication = @publication and originator_id = A.originator_id
and originator_node = A.originator_node and originator_db = A.originator_db
and originator_db_version = A.originator_db_version)

if @@error <> 0
goto UNDO

exec sp_xml_removedocument @DocHandle
if @@error <> 0
goto UNDO

commit tran
return

UNDO:
rollback tran tr_statuscollection_applyres
commit tran
return

end

sp_MSNonSQLDDL (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_MSNonSQLDDL(nvarchar @qual_source_object
, uniqueidentifier @pubid
, nvarchar @columnName
, int @schemasubtype)

MetaData:

 create procedure sys.sp_MSNonSQLDDL(  
@qual_source_object nvarchar(540),
@pubid uniqueidentifier,
@columnName sysname,
@schemasubtype int = 1
)
AS
declare @len int
declare @prec int
declare @scale int
declare @typename nvarchar(270)
declare @objid int
declare @schemaversion int
declare @artname sysname
declare @schemaguid uniqueidentifier
declare @schematype int
declare @retcode int
declare @artid uniqueidentifier
declare @non_qualified_name nvarchar(255)
declare @qual_column nvarchar(255)
declare @is_null int
declare @is_null_string nvarchar(20)
declare @schematext nvarchar(max)
declare @index_id int
declare @column_list nvarchar(4000)
declare @foreign_key_list nvarchar(4000)
declare @reference_column_list nvarchar(4000)
declare @column sysname
declare @parent_column_id int
declare @foreign_key_constid int
declare @reference_column_id int
declare @foreign_key_id int
declare @foreign_key_column sysname
declare @reference_column sysname
declare @colid int
declare @is_identity bit
declare @identity_property nvarchar(1000)
declare @seed_value sql_variant
declare @increment_value sql_variant
declare @referenced_object_id int
declare @constraint_Name sysname
declare @key_ordinal tinyint
declare @default_constraint_definition nvarchar(2000)
declare @default_constraint_name sysname
declare @column_with_default sysname

declare @publisher sysname
declare @publisher_db sysname

declare @is_not_for_replication bit
,@delete_referential_action tinyint
,@update_referential_action tinyint

select @identity_property = NULL
select @qual_column=QUOTENAME(@columnName)
select @seed_value=NULL, @increment_value=NULL
select @objid = object_id(@qual_source_object)

-- enum of constants
declare @schemasubtype_addcolumn int
,@schemasubtype_dropcolumn int
,@schemasubtype_altercolumn int
,@schemasubtype_disabletrigger int
,@schemasubtype_enabletrigger int
,@schemasubtype_disabletriggerall int
,@schemasubtype_enabletriggerall int
,@schemasubtype_dropconstraint int
,@schemasubtype_enableconstraint int
,@schemasubtype_disableconstraint int
,@schemasubtype_enableconstraintall int
,@schemasubtype_disableconstraintall int
,@schemasubtype_addfk int
,@schemasubtype_addun int
,@schemasubtype_addchk int
,@schemasubtype_adddf int
,@schemasubtype_addpk int

select @schemasubtype_addcolumn = 1 -- N'ADDCOLUMN'
,@schemasubtype_dropcolumn = 2 -- N'DROPCOLUMN'
,@schemasubtype_altercolumn = 3 -- N'ALTERCOLUMN'
,@schemasubtype_addpk = 4 -- N'ADDPRIMARYKEY'
,@schemasubtype_addun = 5 -- N'ADDUNIQUE'
,@schemasubtype_addfk = 6 -- N'ADDREFERENCE'
,@schemasubtype_dropconstraint = 7 -- N'DROPCONSTRAINT'
,@schemasubtype_adddf = 8 -- N'ADDDEFAULT'
,@schemasubtype_addchk = 9 -- N'ADDCHECK'
,@schemasubtype_disabletrigger = 10 -- N'DISABLETRIGGER'
,@schemasubtype_enabletrigger = 11 -- N'ENABLETRIGGER'
,@schemasubtype_disabletriggerall = 12 -- N'DISABLETRIGGER'
,@schemasubtype_enabletriggerall = 13 -- N'ENABLETRIGGER'
,@schemasubtype_enableconstraint = 14 -- N'ENABLECONSTRAINT'
,@schemasubtype_disableconstraint = 15 -- N'DISABLECONSTRAINT'
,@schemasubtype_enableconstraintall = 16 -- N'ENABLECONSTRAINT'
,@schemasubtype_disableconstraintall = 17 -- N'DISABLECONSTRAINT'


-- don't worry about non-sql if you don't own this publication
select @publisher=publisher, @publisher_db=publisher_db from dbo.sysmergepublications where pubid=@pubid
if LOWER(@publisher)<>LOWER(publishingservername()) or @publisher_db<>db_name()
return(0)

-- get non-qualified object name for heter- subscribers to use
select @non_qualified_name = QUOTENAME(object_name(objid)),
@artid= artid
from dbo.sysmergearticles where pubid=@pubid and objid=@objid

select @schemaversion = schemaversion from dbo.sysmergeschemachange

if (@schemaversion is NULL)
set @schemaversion = 1
else
select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange

set @schemaguid = newid()
set @schematype = 13 -- schema type for ALTER TABLE for non-SQL subscribers --

if @schemasubtype=@schemasubtype_dropcolumn -- drop column
begin
select @schematext = N'alter table ' + @non_qualified_name + ' drop column ' + @qual_column
end
else if @schemasubtype in (1,3) -- add column and alter column
begin
-- need to change code to use sys.columns category view.
select @typename = case system_type_id when 240 then type_name(user_type_id) else type_name(system_type_id) end,
@len = max_length, @prec = precision,@scale = scale, @is_null=is_nullable
from sys.columns where name=@columnName and object_id=@objid
if @typename='nvarchar' or @typename='nchar' -- a unit of nchar takes 2 bytes
select @len = @len/2
if @is_null = 1
select @is_null_string = N' NULL '
else
select @is_null_string = N' not NULL '

exec @retcode = sys.sp_MSRecontructType @typename out, @len, @prec, @scale
if @@error<>0 OR @retcode <>0
return (1)

declare @definition nvarchar(1024)
set @definition=NULL
select @definition=definition from sys.computed_columns where name=@columnName and object_id=@objid

select @is_identity=is_identity, @colid=column_id from sys.columns where object_id=@objid and name=@columnName
if @is_identity = 1
begin
select @seed_value=seed_value, @increment_value=increment_value from sys.identity_columns
where object_id=@objid and column_id=@colid
if @seed_value is NULL or @increment_value is NULL
raiserror(21263, 16, -1, '@seed_value')
select @identity_property = N'(' + convert(nvarchar, @seed_value) + N',' + convert(nvarchar, @increment_value) + N')'
end
if @schemasubtype = @schemasubtype_addcolumn
begin
if @definition is null
begin
select @schematext = N'alter table ' + @non_qualified_name + ' add ' + @qual_column + N' ' + @typename + N' ' + @is_null_string

-- does this column have a default?
select @default_constraint_name = name, @default_constraint_definition = definition
from sys.default_constraints
where parent_object_id = @objid
and parent_column_id = @colid
and type = 'D'

if @default_constraint_name is not null and @default_constraint_definition is not null
begin
select @schematext = @schematext + N' constraint ' + quotename(@default_constraint_name) +
' default ' + @default_constraint_definition
end
end
else
begin
select @schematext = N'alter table ' + @non_qualified_name + ' add ' + @qual_column + N' as ' + @definition
end
end
else if @schemasubtype = @schemasubtype_altercolumn
select @schematext = N'alter table ' + @non_qualified_name + ' alter column ' + @qual_column + N' ' + @typename + N' ' + @is_null_string
if @is_identity=1 and @identity_property is not NULL
select @schematext = @schematext + N' identity ' + @identity_property
end
else if @schemasubtype = @schemasubtype_addpk -- add primary key
begin
if @columnName=N'' or @columnName is NULL
select @constraint_Name=N'[replication_primary_' + convert(nvarchar(36), newid()) +']'
else
select @constraint_Name = @columnName
select @index_id=index_id from sys.indexes where object_id = @objid and is_primary_key=1
select @column_list = N' ', @column = NULL, @colid=NULL

set @key_ordinal=NULL
select @key_ordinal = min(key_ordinal)
from sys.index_columns
where object_id = @objid
and index_id=@index_id
and key_ordinal>0

while @key_ordinal is not NULL
begin
select @colid = column_id
from sys.index_columns
where object_id = @objid
and index_id=@index_id
and key_ordinal=@key_ordinal

select @column = name from sys.columns where object_id=@objid and column_id = @colid

if @column_list = N' '
select @column_list = @column
else
select @column_list = @column_list + N', ' + @column

select @key_ordinal = min(key_ordinal)
from sys.index_columns
where object_id = @objid
and index_id=@index_id
and key_ordinal>@key_ordinal
and key_ordinal>0
end
select @schematext = N'alter table ' + @non_qualified_name + N' add constraint ' + @constraint_Name
+ N' primary key (' + @column_list + N')'
end
else if @schemasubtype = @schemasubtype_addun -- add unique constraint
begin
if @columnName=N'' or @columnName is NULL
select @constraint_Name=N'[replication_unique_' + convert(nvarchar(36), newid()) +']'
else
select @constraint_Name = @columnName

select @index_id=index_id from sys.indexes where object_id = @objid and is_unique_constraint =1
select @column_list = N' ', @column = NULL, @colid=NULL

set @key_ordinal=NULL
select @key_ordinal = min(key_ordinal)
from sys.index_columns
where object_id = @objid
and index_id=@index_id
and key_ordinal>0

while @key_ordinal is not NULL
begin
select @colid = column_id
from sys.index_columns
where object_id = @objid
and index_id=@index_id
and key_ordinal=@key_ordinal

select @column = name from sys.columns where object_id=@objid and column_id = @colid
if @column is NULL
raiserror(14043, 16, 1, '@column', 'sp_MSNonSQLDDL')
if @column_list = N' '
select @column_list = @column
else
select @column_list = @column_list + N', ' + @column

select @key_ordinal = min(key_ordinal)
from sys.index_columns
where object_id = @objid
and index_id=@index_id
and key_ordinal>@key_ordinal
and key_ordinal>0
end
select @schematext = N'alter table ' + @non_qualified_name + N' add constraint ' + @constraint_Name
+ ' unique (' + @column_list + N')'
end
else if @schemasubtype=@schemasubtype_addfk -- add reference
begin
if @columnName=N'' or @columnName is NULL
select @constraint_Name=N'[replication_foreign_' + convert(nvarchar(36), newid()) + ']'
else
select @constraint_Name = @columnName
select @constraint_Name = QUOTENAME(@constraint_Name)
select @schematext = N' '
select @foreign_key_constid = NULL

-- can not use TOP 1 here, as the result won't be NULL when done. Same below
-- @columnName = N'' means that it is a column level foreign key; otherwise, we qualify with constraint name of @columnName

select @foreign_key_constid = min(constraint_object_id) from sys.foreign_key_columns
where parent_object_id=@objid and (@columnName=N'' or @columnName = object_name(constraint_object_id))
while (@foreign_key_constid is not NULL)
begin
select @reference_column_list=N' ', @foreign_key_list=N' '
select @parent_column_id = NULL, @reference_column_id = NULL
select @parent_column_id = min(parent_column_id) from sys.foreign_key_columns
where parent_object_id=@objid and constraint_object_id = @foreign_key_constid
while (@parent_column_id is not NULL)
begin
select @reference_column_id=referenced_column_id, @referenced_object_id=referenced_object_id from sys.foreign_key_columns
where parent_object_id=@objid and constraint_object_id = @foreign_key_constid and parent_column_id=@parent_column_id
select @reference_column = name from sys.columns where object_id=@referenced_object_id and column_id=@reference_column_id
select @foreign_key_column=name from sys.columns where object_id=@objid and column_id=@parent_column_id
if @reference_column_list = N' '
select @reference_column_list = @reference_column
else
select @reference_column_list = @reference_column_list + N',' + @reference_column
if @foreign_key_list = N' '
select @foreign_key_list = @foreign_key_column
else
select @foreign_key_list = @foreign_key_list + N',' + @foreign_key_column
select @parent_column_id = min(parent_column_id) from sys.foreign_key_columns
where parent_object_id=@objid and constraint_object_id = @foreign_key_constid and parent_column_id > @parent_column_id
end

if @schematext = N' '
select @schematext = N'alter table ' + @non_qualified_name + N' add constraint ' + @constraint_Name
+ N' foreign key (' + @foreign_key_list + N') references ' + object_name(@referenced_object_id) + N' (' + @reference_column_list + N' ) '
else
select @schematext = @schematext + N', constraint ' + @constraint_Name +
N' foreign key (' + @foreign_key_list + N') references ' +
object_name(@referenced_object_id) + N' (' + @reference_column_list + N' ) '

-- check if we need to add CASCADE attribute
select @is_not_for_replication=is_not_for_replication,
@delete_referential_action=delete_referential_action,
@update_referential_action=update_referential_action
from sys.foreign_keys
where parent_object_id = @objid and name=@columnName

if @delete_referential_action in (1,2,3)
begin
select @schematext = @schematext + N'on delete ' +
case @delete_referential_action
when 1 then N'cascade '
when 2 then N'set null '
when 3 then N'set default '
end
end

if @update_referential_action in (1,2,3)
begin
select @schematext = @schematext + N'on update ' +
case @update_referential_action
when 1 then N'cascade '
when 2 then N'set null '
when 3 then N'set default '
end
end

if @is_not_for_replication = 1
begin
select @schematext = @schematext + N'not for replication '
end

select @foreign_key_constid = min(constraint_object_id) from sys.foreign_key_columns
where parent_object_id=@objid and (@columnName=N'' or @columnName = object_name(constraint_object_id))
and constraint_object_id > @foreign_key_constid
end
end
else if @schemasubtype = @schemasubtype_dropconstraint -- drop constraint
begin
-- removed this for bug 686296
-- N' if object_id(''' +@qual_column+ N''') is not null ' +
select @schematext =
N'alter table ' + @non_qualified_name + ' drop constraint ' + @qual_column
end
else if @schemasubtype = @schemasubtype_adddf -- add default constraint
begin
if @columnName=N'' or @columnName is NULL
select @constraint_Name=N'[replication_default_' + convert(nvarchar(36), newid()) +']'
else
select @constraint_Name = @columnName

select @default_constraint_definition = dc.definition, @column_with_default = c.name
from sys.default_constraints dc join sys.columns c
on dc.parent_object_id = c.object_id
and dc.parent_column_id = c.column_id
and dc.name = @constraint_Name

-- if we added the column for this default in this same ALTER TABLE statement, then we would have
-- already posted an ALTER TABLE ADD COLUMN x DEFAULT y - so no need to post a separate ALTER TABLE ADD DEFAULT.

if object_id(N'tempdb..#merge_altertable', 'U') is not null
begin
if exists (select * from #merge_altertable where ColumnName = @column_with_default
and TableName = object_name(@objid)
and DDLsubtype = N'ADDCOLUMN')
return 0
end

select @schematext = N'alter table ' + @non_qualified_name + N' add constraint ' + quotename(@constraint_Name)
+ N' default ' + @default_constraint_definition + N' for ' + quotename(@column_with_default)
end
else
select @schematext = N' ' -- place-holder for alter column

exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext, @schemasubtype
if @@ERROR<>0 or @retcode<>0
begin

raiserror(21533, 16, -1)
return (1)
end
return (0)

sp_MSproxiedmetadata (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_MSproxiedmetadata(int @tablenick
, uniqueidentifier @rowguid
, varbinary @proxied_lineage
, varbinary @proxied_colv
, bit @proxy_logical_record_lineage
, int @compatlevel)

MetaData:

 create procedure sys.sp_MSproxiedmetadata  
@tablenick int,
@rowguid uniqueidentifier,
@proxied_lineage varbinary(311),
@proxied_colv varbinary(2953),
@proxy_logical_record_lineage bit,
@compatlevel int = 10 -- backward compatibility level, default=Sphinx

as
declare @local_lineage varbinary(311)
declare @local_version int
declare @proxied_version int
declare @incontents tinyint
declare @retcode int

-- Security Checking
-- PAL user access
exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
if (@retcode <> 0) or (@@error <> 0)
return 1

set @proxied_version = {fn GETMAXVERSION(@proxied_lineage)}

if (@proxy_logical_record_lineage = 0)
select @local_lineage = lineage from dbo.MSmerge_contents
where tablenick = @tablenick and rowguid = @rowguid
else
select @local_lineage = logical_record_lineage from dbo.MSmerge_contents
where tablenick = @tablenick and rowguid = @rowguid

if @local_lineage is not null
set @incontents= 1
else
begin

-- cannot proxy if logical record parent row is no longer in contents.
-- if (@proxy_logical_record_lineage = 1)
-- return (0)

if (@proxy_logical_record_lineage = 0)
select @local_lineage = lineage from dbo.MSmerge_tombstone
where tablenick = @tablenick and rowguid = @rowguid
else
select @local_lineage = logical_record_lineage from dbo.MSmerge_tombstone
where tablenick = @tablenick and rowguid = @rowguid

if @local_lineage is not null
set @incontents= 0
else
return(0)
end

set @local_version= {fn GETMAXVERSION(@local_lineage)}

-- make sure that local lineage was not updated since the publisher proxied its last change
-- if it was updated, we leave it unchanged
if @local_version <= @proxied_version
begin
if @compatlevel < 90
begin
if @proxied_lineage is not null
set @proxied_lineage= {fn LINEAGE_80_TO_90(@proxied_lineage)}
if @proxied_colv is not null and @proxy_logical_record_lineage = 0
set @proxied_colv= {fn COLV_80_TO_90(@proxied_colv)}
end

if @incontents = 1
begin
if (@proxy_logical_record_lineage = 0)
update dbo.MSmerge_contents with (rowlock) set lineage = @proxied_lineage, colv1 = @proxied_colv
where tablenick = @tablenick and rowguid = @rowguid and
-- lineage compare makes sure lineage has not changed since @local_lineage was retrieved
lineage = @local_lineage
else
update dbo.MSmerge_contents with (rowlock) set logical_record_lineage = @proxied_lineage
where tablenick = @tablenick and rowguid = @rowguid and
-- logical_record_lineage compare makes sure lineage has not changed since @local_lineage was retrieved
logical_record_lineage = @local_lineage
end
else
begin
if (@proxy_logical_record_lineage = 0)
update dbo.MSmerge_tombstone with (rowlock) set lineage = @proxied_lineage
where tablenick = @tablenick and rowguid = @rowguid and
-- lineage compare makes sure lineage has not changed since @local_lineage was retrieved
lineage = @local_lineage
else
update dbo.MSmerge_tombstone with (rowlock) set logical_record_lineage = @proxied_lineage
where tablenick = @tablenick and rowguid = @rowguid and
-- logical_record_lineage compare makes sure lineage has not changed since @local_lineage was retrieved
logical_record_lineage = @local_lineage
end
end

return (0)

sp_MSprofile_in_use (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_MSprofile_in_use(nvarchar @tablename
, int @profile_id)

MetaData:

 CREATE PROCEDURE sys.sp_MSprofile_in_use   
(
@tablename nvarchar(255),
@profile_id int
)
AS
begin
DECLARE @usage_count int

--
-- security check
-- only db_owner can execute this
--
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end

IF @tablename IS NULL OR @profile_id IS NULL
return 1 ;

IF @tablename = 'MSsnapshot_agents'
SELECT @usage_count = count(*) FROM MSsnapshot_agents
WHERE profile_id = @profile_id
ELSE IF @tablename = 'MSlogreader_agents'
SELECT @usage_count = count(*) FROM MSlogreader_agents
WHERE profile_id = @profile_id
ELSE IF @tablename = 'MSdistribution_agents'
SELECT @usage_count = count(*) FROM MSdistribution_agents
WHERE profile_id = @profile_id
ELSE IF @tablename = 'MSmerge_agents'
SELECT @usage_count = count(*) FROM dbo.MSmerge_agents
WHERE profile_id = @profile_id
ELSE
SELECT @usage_count = 0

IF @usage_count = 0
RETURN -1
ELSE
RETURN 0
end

sp_MSprepare_mergearticle (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_MSprepare_mergearticle(nvarchar @source_owner
, nvarchar @source_table
, nvarchar @publication
, nvarchar @qualified_tablename)

MetaData:

 create procedure sys.sp_MSprepare_mergearticle  
@source_owner sysname,
@source_table sysname, -- table name --
@publication sysname,
@qualified_tablename nvarchar(270)
as
declare @retcode int
declare @id int
declare @qualified_name nvarchar(270)
declare @pubid uniqueidentifier
declare @article_status tinyint
declare @snapshot_ready tinyint
declare @article sysname

set nocount on

-- Security check
if 1 <> is_member('db_owner')
begin
raiserror(15247,-1,-1)
return 1
end

-- Security check
exec @retcode= dbo.sp_MSreplcheck_publish
if @@error <> 0 or @retcode <> 0 return (1)

select @pubid = pubid, @snapshot_ready = snapshot_ready
from dbo.sysmergepublications
where name=@publication and upper(publisher)=upper(publishingservername()) and publisher_db=db_name()

select @qualified_name = QUOTENAME(@source_owner) + '.' + QUOTENAME(@source_table)
select @id = object_id(@qualified_name)

select top 1 @article_status = sma.status
from dbo.sysmergearticles sma join dbo.sysmergepublications smp
on sma.pubid = smp.pubid
where sma.objid = @id

if @snapshot_ready = 2 or (@article_status <> 2 and @article_status <> 6)
begin

-- addguidcolumn needs to be called even if article is active. This is needed to
-- drop and recreate rowguid default constraint - to make it go back and forth
-- between newid() and newsequentialid().
exec @retcode = sys.sp_MSaddguidcolumn @source_owner, @source_table
if @@error <> 0 or @retcode <> 0
return (1)
end

select @article_status = status, @article = name
from dbo.sysmergearticles where objid=@id and pubid=@pubid

if (@article_status = 2 or @article_status = 6) and @snapshot_ready = 1
return 0

begin tran
save tran prep_merge_article

exec @retcode = sys.sp_MSaddguidindex @publication, @source_owner, @source_table
if @@error <> 0 or @retcode <> 0
goto FAILURE

exec @retcode = sys.sp_MSsetup_publisher_idrange @publication, @source_table, @source_owner
if @@error <> 0 or @retcode <> 0
goto FAILURE

-- snapshot will separately call creating the triggers
-- exec @retcode = sys.sp_MSaddmergetriggers @qualified_tablename
-- if @@error <> 0 or @retcode <> 0
-- goto FAILURE

commit tran
return 0

FAILURE:
rollback tran prep_merge_article
raiserror(20714, 10, -1, @article, @publication)
return 1

sp_MSprep_exclusive (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_MSprep_exclusive(nvarchar @objname
, int @objid)

MetaData:

 create procedure sys.sp_MSprep_exclusive   
@objname sysname
,@objid int = NULL
as
set nocount on
declare @retcode int
,@tran_pubname sysname

EXEC @retcode = sys.sp_MSreplcheck_publish
IF @@ERROR <> 0 or @retcode <> 0
return (1)

if @objname is NULL
begin
RAISERROR (14043, 16, -1, '@objname', 'sp_MSprep_exclusive')
return (1)
end

if(@objid is NULL)
begin
select @objid = object_id(@objname)
if @objid is NULL
begin
raiserror(14027, 16, -1, @objname)
return (1)
end

exec sys.sp_replupdateschema @objname
if @@ERROR<>0
return (1)
end

declare #trancolumn CURSOR LOCAL FAST_FORWARD for
select p.name from sysarticles a join
syspublications p on p.pubid = a.pubid
where a.objid=@objid
open #trancolumn
fetch #trancolumn into @tran_pubname
while (@@fetch_status <> -1)
BEGIN
EXEC @retcode = sys.sp_getapplock @Resource = @tran_pubname,
@LockMode = N'Exclusive',
@LockOwner = N'Transaction',
@LockTimeout = 0,
@DbPrincipal = N'db_owner' -- Note that we already require db_owner due to security check at the beginning of the stored procedure.
if @retcode = -1
begin
raiserror(21386, 16, -1, @objname)
goto FAILURE
end
if @@ERROR<>0 or @retcode < 0
goto FAILURE
fetch #trancolumn into @tran_pubname
END
close #trancolumn
deallocate #trancolumn
return 0
FAILURE:
return (1)

sp_MSpostapplyscript_forsubscriberprocs (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_MSpostapplyscript_forsubscriberprocs(nvarchar @procsuffix)

MetaData:

 --  This proc is called by the .prc file to mark merge replication objects as system objects.  
create procedure sys.sp_MSpostapplyscript_forsubscriberprocs (
@procsuffix sysname)

as
begin
declare @retcode smallint
declare @procname nvarchar(400)
declare @ownername nvarchar(140)
declare @destowner nvarchar(140)
declare @ins_procname nvarchar(258)
declare @ins_batch_procname nvarchar(258)
declare @upd_procname nvarchar(258)
declare @upd_batch_procname nvarchar(258)
declare @sel_procname nvarchar(258)
declare @sel_metadata_procname nvarchar(258)
declare @del_procname nvarchar(258)
declare @conflict_proc nvarchar(258)

set nocount on
--
-- Check to see if current publication has permission
--
exec @retcode=sys.sp_MSreplcheck_subscribe
if @retcode<>0 or @@ERROR<>0 return (1)

select @ins_procname = quotename('MSmerge_ins_sp_' + @procsuffix)
select @ins_batch_procname = quotename('MSmerge_ins_sp_' + @procsuffix + '_batch')
select @upd_procname = quotename('MSmerge_upd_sp_' + @procsuffix)
select @upd_batch_procname = quotename('MSmerge_upd_sp_' + @procsuffix + '_batch')
select @del_procname = quotename('MSmerge_del_sp_' + @procsuffix)
select @sel_procname = quotename('MSmerge_sel_sp_' + @procsuffix)
select @sel_metadata_procname = quotename('MSmerge_sel_sp_' + @procsuffix + '_metadata')
select @conflict_proc = quotename('MSmerge_cft_sp_' + @procsuffix)

select @procname = @ins_procname
if object_id(@ins_procname ,'P') is not NULL
begin
exec sys.sp_MS_marksystemobject @procname
exec ('grant exec on ' + @procname + ' to public')
end

select @procname = @ins_batch_procname
if object_id(@ins_batch_procname ,'P') is not NULL
begin
exec sys.sp_MS_marksystemobject @procname
exec ('grant exec on ' + @procname + ' to public')
end

select @procname = @upd_procname
if object_id(@upd_procname ,'P') is not NULL
begin
exec sys.sp_MS_marksystemobject @procname
exec ('grant exec on ' + @procname + ' to public')
end

select @procname = @upd_batch_procname
if object_id(@upd_batch_procname ,'P') is not NULL
begin
exec sys.sp_MS_marksystemobject @procname
exec ('grant exec on ' + @procname + ' to public')
end

select @procname = @del_procname
if object_id(@del_procname ,'P') is not NULL
begin
exec sys.sp_MS_marksystemobject @procname
exec ('grant exec on ' + @procname + ' to public')
end

select @procname = @sel_procname
if object_id(@sel_procname ,'P') is not NULL
begin
exec sys.sp_MS_marksystemobject @procname
exec ('grant exec on ' + @procname + ' to public')
end

select @procname = @sel_metadata_procname
if object_id(@sel_metadata_procname ,'P') is not NULL
begin
exec sys.sp_MS_marksystemobject @procname
exec ('grant exec on ' + @procname + ' to public')
end

select @procname = @conflict_proc
if object_id(@conflict_proc ,'P') is not NULL
begin
exec sys.sp_MS_marksystemobject @procname
exec ('grant exec on ' + @procname + ' to public')
end
end

Total Pageviews