EXEMPLO_1212310
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_criatriggers
Parameters
Name
Type
Mode
Definition
CREATE procedure sp_criatriggers as declare @nometabela sysname declare @idtabela int declare @idlog int declare @usrlog varchar(255) declare @processolog varchar(100) declare @contextinfo varchar(300) declare @nometabelacomp varchar(30) declare @networkuser varchar(100) declare @machinename varchar(100) declare @machineip varchar(50) declare cursor_tabelas cursor for select distinct c.name,c.id from sysobjects c, zlogcampos x where xtype='U' and name<>'ZLOG' and logativo = 'S' and c.name COLLATE SQL_Latin1_General_CP1_CI_AI = x.tabela COLLATE SQL_Latin1_General_CP1_CI_AI and c.uid = SCHEMA_ID() if (select LOGATIVO FROM ZLOGPARAMS) = 'S' select @contextinfo = context_info from sysprocesses where spid = @@spid if @contextinfo = 0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 set @usrlog= host_Name() else begin DECLARE @contextinfostring AS VARCHAR(500) SET @contextinfostring = convert(varchar(500), @contextinfo) SELECT * INTO #CURSOR FROM SPLIT(';', @contextinfostring) SELECT @usrlog = VALUE FROM #CURSOR WHERE ROWID = 1 SELECT @processolog = VALUE FROM #CURSOR WHERE ROWID = 2 SELECT @networkuser = VALUE FROM #CURSOR WHERE ROWID = 3 SELECT @machinename = VALUE FROM #CURSOR WHERE ROWID = 4 SELECT @machineip = VALUE FROM #CURSOR WHERE ROWID = 5 DROP TABLE #CURSOR end begin insert into zlog (tabela,coluna,dthora,usuario,valor,valorantigo,tiposql,chave,processo,networkuser,machinename,machineip) values ('ZLOGPARAMS','ATIVO',GETDATE(),@usrlog, 'S','N','U','CODIGO=1','Ativa Log',@networkuser,@machinename,@machineip) open cursor_tabelas fetch next from cursor_tabelas into @nometabela,@idtabela while @@fetch_status=0 begin set @nometabelacomp = @nometabela; if (len(@nometabelacomp) >= 20) set @nometabelacomp = '_' + substring (@nometabelacomp, len(@nometabelacomp)-19, 30) execute sp_montatriggerdelete @nometabela execute sp_montatriggerinsert @nometabela IF not EXISTS (SELECT name FROM sysobjects WHERE name = 'logupdate'+@nometabelacomp AND type = 'TR') execute sp_montatriggerupdate @nometabela fetch next from cursor_tabelas into @nometabela,@idtabela end close cursor_tabelas deallocate cursor_tabelas end