Hola Javier...
o el que tenga la respuesta.
Estuve revisando este hilo y me fui hasta la pagina de portalSql, donde esta
el articulo de cazaInstrucciones y tome el modelo para una tabla mia y me
esta dando este error:
Servidor: mensaje 111, nivel 15, estado 1, línea 5
'CREATE TRIGGER' must be the first statement in a query batch.
este es el modelo, ajustado a mi necesidad.
use bd
go
if not object_id('Bitacora') is null
drop table Bitacora
go
CREATE TABLE [dbo].[Bitacora] (
idUsuario int not null default @@spid primary key,
[Usuario] [varchar] (50) NOT NULL default suser_sname() ,
[EventType] [char] (20) NOT NULL ,
[Status] [int] NOT NULL ,
[EventInfo] [varchar] (4000) NOT NULL ,
[Fecha] [smalldatetime] NOT NULL default getdate()
)
GO
/* Trigger de Monitoreo */
if not object_id('trig_tablabitacora') is null
DROP TRIGGER trig_tablabitacora
CREATE TRIGGER trig_tablabitacora
ON tbldetmov
FOR DELETE, INSERT, UPDATE
AS
BEGIN
DECLARE @NUMERO INT
create Table #t(idusuario int not null default @@spid,
EventType char (14) NOT NULL ,
Status int NOT NULL ,
EventInfo varchar (1000) NOT NULL)
INSERT INTO #t (EventType,Status,EventInfo)
exec sp_executesql N'DBCC INPUTBUFFER( @i )', N'@i int',
@i=@@spid
update b set b.EventType=t.EventType,
b.Status = t.Status,
b.EventInfo=t.EventInfo
from Bitacora b inner join #t t on b.idusuario=t.idusuario
if @@rowcount=0
begin
insert into bitacora (EventType,Status,EventInfo) select
left(EventType,14),Status,left(EventInfo,100) from #t
end
END
go
Me gustaria Implementarlo y entenderlo bien. me parece muy interesante.
Luis
Leer las respuestas