Se pierden Transacciones

22/09/2004 - 20:29 por luis suescun | Informe spam
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

#1 Gustavo Larriera [MVP]
22/09/2004 - 20:40 | Informe spam
Verifica que la sentencia previa a cada CREATE TRIGGER sea un GO (es el
terminador de query batch).

Gustavo Larriera, MVP
Uruguay LatAm
http://sqljunkies.com/weblog/gux/
Este mensaje se proporciona "COMO ESTA" sin garantias y no otorga ningun
derecho / This posting is provided "AS IS" with no warranties, and confers
no rights.
"luis suescun" wrote in message
news:
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



Preguntas similares