Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   Validar Evento En Trigger (https://www.clubdelphi.com/foros/showthread.php?t=68984)

ingmichel 19-07-2010 17:20:06

Validar Evento En Trigger
 
Hola Como Estan Todos, Estoy Haciendo Un Trigger Y Requiero Saber Cual Evento Se Esta Capturando En Un Momento Determinado, Es Decir Si Se Esta Insertando O Moficando, La Logica Seria La Siguente

Create Trigger Tg_audita On Mitabla
For Insert,update
As
Declare @evento As Varchar(30)

If "si Se Esta Insertando" //si Es Un Insert
Begin
Set @evento='inserto Registro'
End
Else
If "si Se Esta Modificando" // Si Es Un Update
Begin
Set @evento='modifico Registro'

End

Insert Into Auditor(fecha_registro,evento)
Values(getdate(),@evento)
End


Estoy Utilizando El Motor Sql Server 2000
Con Esto Kiero Evitar Hacer Dos Triggers Y Hacerlo En Uno Gracias De Antemano.

Axel_Tech 26-07-2010 09:52:42

No lo he probado, pero puedes mirar si el valor antiguo del campo de la clave primaria de Mitabla es igual al nuevo, por lo tanto sería un update (asumiendo que la clave primaria nunca la vas a cambiar), y si no es igual (el antiguo sería null) es un insert. Modifico tu código:
Código:

If campoClave.old <> campoClave.new //si Es Un Insert
  Set @evento='inserto Registro'
Else
  Set @evento='modifico Registro'



La franja horaria es GMT +2. Ahora son las 00:45:17.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi