USP_BBNC_ENABLETRIGGERS

Executes the "NetCommunity Triggers: Enable" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being updated.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the update.

Definition

Copy


                        CREATE procedure dbo.USP_BBNC_ENABLETRIGGERS(@ID as uniqueidentifier, @CHANGEAGENTID as uniqueidentifier)
                        with execute as owner
                        as
                            set nocount on;

                            declare @TOTALROWS int;
                            declare @ROWCOUNT int;
                            declare @TRIGGERNAME sysname;
                            declare @TABLENAME sysname;
                            declare @SQL nvarchar(max);
                            declare @TABLES table 
                                ( 
                                ROWNUM int identity (1, 1) primary key not null ,
                                TRIGGERNAME sysname,
                                TABLENAME sysname 
                                ) ;

                            insert into @TABLES (TRIGGERNAME, TABLENAME)
                                select 
                                    [NAME], object_name(PARENT_ID)
                                from 
                                    sys.TRIGGERS 
                                where 
                                    [NAME] like 'TR_%BBNC%IDMAP';

                            select @TOTALROWS = count(*) from @TABLES;

                            set @ROWCOUNT = 1;

                            while @ROWCOUNT <= @TOTALROWS 
                                begin 

                                    select 
                                        @TRIGGERNAME = TRIGGERNAME,
                                        @TABLENAME = TABLENAME
                                    from
                                        @TABLES
                                    where
                                        ROWNUM = @ROWCOUNT;

                                    set @SQL = N'alter table [dbo].[' + @TABLENAME + N'] enable trigger ' + @TRIGGERNAME;
                                    exec sp_executesql @SQL;

                                    set @ROWCOUNT = @ROWCOUNT + 1;
                                end;

                            return 0;