-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanEntrenamientoAudit.sql
More file actions
26 lines (24 loc) · 1.12 KB
/
planEntrenamientoAudit.sql
File metadata and controls
26 lines (24 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
CREATE TRIGGER TR_PlanEntrenamiento_Audit
ON PlanEntrenamiento
AFTER INSERT, UPDATE, DELETE
AS
BEGIN
IF EXISTS (SELECT * FROM inserted)
BEGIN
INSERT INTO PlanEntrenamiento_Audit (id_plan_entrenamiento, id_entrenador, precio, descripcion, plan_entrenamiento_inactivo, operation_type)
SELECT id_plan_entrenamiento,id_entrenador, precio, descripcion, plan_entrenamiento_inactivo, 'I'
FROM inserted;
END
IF EXISTS (SELECT * FROM deleted)
BEGIN
INSERT INTO PlanEntrenamiento_Audit (id_plan_entrenamiento, id_entrenador, precio, descripcion, plan_entrenamiento_inactivo, operation_type)
SELECT id_plan_entrenamiento, id_entrenador, precio, descripcion, plan_entrenamiento_inactivo, 'D'
FROM deleted;
END
IF EXISTS (SELECT * FROM inserted) AND EXISTS (SELECT * FROM deleted)
BEGIN
INSERT INTO PlanEntrenamiento_Audit (id_plan_entrenamiento, id_entrenador, precio, descripcion, plan_entrenamiento_inactivo, operation_type)
SELECT id_plan_entrenamiento, id_entrenador, precio, descripcion, plan_entrenamiento_inactivo, 'U'
FROM inserted;
END
END;