May 2, 2012

sp_MS_marksystemobject (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_MS_marksystemobject(nvarchar @objname
, varchar @namespace)

MetaData:

   
-- -- -- -- -- -- -- -- -- -- -- -- -- -- sp_MS_marksystemobject -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
-- FOR INTERNAL USE ONLY ... DO NOT DOCUMENT --
-- This procedure sets a bit in sysobjects. This bit has no meaning, various
-- groups (starfigther, davinci, replication) use it for different things
-- MSQL makes no warranty, express or implied, on what objects will or will
-- not have this bit set. Use at your own risk.
--
create procedure sys.sp_MS_marksystemobject
@objname nvarchar(517), -- 517 is max for two part name
@namespace varchar(10) = NULL -- database, server or null
as

set nocount on
declare @objid int
declare @owner sysname,
@ns int, -- namespace enumeration value
@object sysname

-- ============================================================
-- DEVNOTE:
-- x_eonc_TrgOnServer = 20, // Namespace for Triggers on the Server
-- x_eonc_TrgOnDatabase = 21, // Namespace for Triggers on Databases
-- x_eonc_Standard = 0 // Standard Namespace
-- ============================================================

if not (@namespace is NULL)
begin
select @ns = (case lower(@namespace)
when 'server' then 20
when 'database' then 21
end)
end
else
begin
set @ns = 0 -- null means standard namespace
end

-- bail out on invalid namespace.
if @ns is null
begin
raiserror('sp_MS_marksystemobject: Invalid NameSpace ''%ls''',0,1,@namespace)
return (1)
end

-- CHECK THE OBJECT NAME --
select @object = parsename(@objname, 1),
@owner = parsename(@objname, 2)

-- ============================================================
-- DEVNOTE:
-- x_eonc_TrgOnServer = 20, // Namespace for Triggers on the Server
-- x_eonc_TrgOnDatabase = 21, // Namespace for Triggers on Databases
-- ============================================================

if @ns = 20 or @ns = 21
begin
if NOT (@owner is null)
begin
-- schema name specified for extended trigger. Error out
raiserror(1094,-1,-1)
return (1)
end
end

-- use master db for server level trigger
if @ns = 20
begin
select @objid = object_id from sys.server_triggers where name = @objname
end
else if @ns = 21
begin
select @objid = object_id from sys.triggers where name = @objname and parent_class = 0
end
else
begin
select @objid = object_id(@objname, 'local')
end


-- CHECK THE OBJECT OWNER (MUST BE DBO) --
-- DO THE UPDATE --
BEGIN TRAN
if not (@objid is null)
begin
if @ns = 0
begin
EXEC %%Object(MultiName = @objname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
if @@error <> 0
select @objid = null
else
begin
if @owner is null
select @owner = N'dbo'

EXEC %%Object( Owner = @owner, Name = @object ).SetSystem()

end
end
else
begin
EXEC %%TriggerEx(MultiName = @objname).ValidateAndSetSystem(
ID = @objid, NameSpaceClass = @ns)
end
end

if @objid is null
begin
raiserror('sp_MS_marksystemobject: Invalid object name ''%ls''',0,1,@objname)
COMMIT TRAN
return (1)
end

COMMIT TRAN
return (0) -- sp_MS_marksystemobject

No comments:

Post a Comment

Total Pageviews