June 4, 2012

sp_MSupdate_agenttype_default (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_MSupdate_agenttype_default(int @profile_id)

MetaData:

   
-- Set a profile as a default for an agent_type
create procedure sys.sp_MSupdate_agenttype_default(
@profile_id int
)
as
set nocount on

declare @agent_type int

-- Security Check: require sysadmin
if (isnull(is_srvrolemember('sysadmin'),0) = 0)
begin
raiserror(21089,16,-1)
return (1)
end

-- This profile must have been defined for this agent type --
if not exists ( select * from msdb.dbo.MSagent_profiles
where profile_id = @profile_id )
BEGIN
RAISERROR (20066, 16, -1) -- profile not defined
RETURN (1)
END


select @agent_type = agent_type
from msdb.dbo.MSagent_profiles
where profile_id = @profile_id

BEGIN TRAN

update msdb.dbo.MSagent_profiles
set def_profile = 0
where agent_type = @agent_type
and def_profile = 1

if @@error <> 0
goto UNDO

update msdb.dbo.MSagent_profiles
set def_profile = 1
where profile_id = @profile_id

if @@error <> 0
goto UNDO

COMMIT TRAN

return 0

UNDO:
if @@trancount = 1
rollback tran
else
commit tran

return 1

No comments:

Post a Comment

Total Pageviews