April 30, 2012

sp_helptrigger (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_helptrigger(nvarchar @tabname
, char @triggertype)

MetaData:

 create procedure sys.sp_helptrigger  
@tabname nvarchar(776), -- Table name
@triggertype char(6) = NULL -- Trigger type
as

declare @objid int, -- id of the object --
@dbname sysname

-- Check to see that the object names are local to the current database.
select @dbname = parsename(@tabname,3)
,@triggertype = UPPER (@triggertype collate Latin1_General_CI_AS)
if @dbname is null
select @dbname = db_name()
else if @dbname <> db_name()
begin
raiserror(15250,-1,-1)
return (1)
end

select @objid = object_id from sys.objects where object_id = object_id(@tabname) and type in ('U', 'V')
if @objid is null
begin
raiserror(15009,-1,-1,@tabname,@dbname)
return(1)
end

-- Check that input type is update, INSERT, DELETE --
if @triggertype is not null and not @triggertype in ('UPDATE', 'INSERT', 'DELETE')
begin
raiserror(15305,-1,-1)
return(1)
end

select
trigger_name = name,
trigger_owner = user_name(ObjectProperty( object_id, 'ownerid')),
isupdate = ObjectProperty( object_id, 'ExecIsUpdateTrigger'),
isdelete = ObjectProperty( object_id, 'ExecIsDeleteTrigger'),
isinsert = ObjectProperty( object_id, 'ExecIsInsertTrigger'),
isafter = ObjectProperty( object_id, 'ExecIsAfterTrigger'),
isinsteadof = ObjectProperty( object_id, 'ExecIsInsteadOfTrigger'),
trigger_schema = schema_name(schema_id)
from sys.objects
where parent_object_id = @objid and type IN ('TR','TA')
AND ( @triggertype is NULL
OR ( @triggertype = 'DELETE' AND ObjectProperty( object_id, 'ExecIsDeleteTrigger') = 1 )
OR ( @triggertype = 'INSERT' AND ObjectProperty( object_id, 'ExecIsInsertTrigger') = 1 )
OR ( @triggertype = 'UPDATE' AND ObjectProperty( object_id, 'ExecIsUpdateTrigger') = 1 ) )

return(0) -- sp_helptrigger

No comments:

Post a Comment

Total Pageviews