Se me ocurre hacer un trigger que se dispare cuando haya un evento delete, pero no sé como hacer para que efectivamente me borre el registro pero por otro lado me lo copie tal cual a otra tabla que sería como un log de lo eliminado.
Mi tabla de gestiones sólo cuenta con los campos:
Código:
De momento tengo lo siguiente pero me funciona sólo en SQL Server:idgestion | usgestion | detalle | fecha_creacion
Código:
Espero me puedan ayudar! CREATE TRIGGER triDeleteGestion
ON gestion
INSTEAD OF DELETE
AS
BEGIN
DECLARE @idgestion INT
DECLARE @us INT
DECLARE @detalle TEXT
DECLARE @fecha TIMESTAMP
SELECT @idgestion = (SELECT idgestion FROM DELETED)
SELECT @us = (SELECT usgestion FROM DELETED)
SELECT @detalle = (SELECT detalle FROM DELETED )
SELECT @fecha = (SELECT fecha_creacion FROM DELETED)
IF( @idgestion <> '')
BEGIN
INSERT INTO log_gestion( idgestion, usgestion, detalle, fecha_creacion )
VALUES(@idgestion, @us, @detalle, @fecha)
END
ELSE
BEGIN
RAISERROR('La gestión no existe')
END
END


