April 16, 2012

sp_altermessage (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_altermessage(int @message_id
, nvarchar @parameter
, varchar @parameter_value)

MetaData:

 create procedure sys.sp_altermessage  
@message_id int,
@parameter sysname,
@parameter_value varchar(5)
as
declare @msg varchar(128)
declare @log bit
select @parameter = UPPER (@parameter collate Latin1_General_CI_AS)
select @parameter_value = UPPER (@parameter_value collate Latin1_General_CI_AS)

-- Must be ServerAdmin to manage messages
if is_srvrolemember('serveradmin') = 0
begin
raiserror(15247,-1,-1)
return (1)
end

-- Is Parameter 'WITH_LOG'?
if (@parameter <> 'WITH_LOG')
begin
raiserror(15176,-1,-1)
return (1)
end

-- Is ParameterValue TRUE or FALSE?
select @log = (case @parameter_value
when 'TRUE' then 1
when 'FALSE' then 0
end)
if @log is null
begin
raiserror(15277,-1,-1)
return (1)
end

BEGIN TRANSACTION
-- Does this message exist?
EXEC %%ErrorMessage(ID = @message_id).Lock(Exclusive = 1)
if @@error <> 0
begin
COMMIT TRANSACTION
raiserror(15179,-1,-1,@message_id)
return (1)
end

declare @msg_str nvarchar(50)
set @msg_str = @message_id

-- Turn event log on or off
EXEC %%ErrorMessage(ID = @message_id).SetEventLog(EventLog = @log)

-- EMDEventType(x_eet_Alter_Message), EMDUniversalClass(x_eunc_Message), src major id, src minor id, src name
-- -1 means ignore target stuff, target major id, target minor id, target name,
-- # of parameters, 5 parameters
EXEC %%System().FireTrigger(ID = 215, ID = 106, ID = @message_id, ID = 0, Value = @msg_str,
ID = -1, ID = 0, ID = 0, Value = NULL,
ID = 3, Value = @message_id, Value = @parameter, Value = @parameter_value, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

COMMIT TRANSACTION

return (0) -- sp_altermessage

No comments:

Post a Comment

Total Pageviews