Base
INGENIERÍA DE INFORMÁTICA Y DE SISTEMAS
BASE DE DATOS II
Los
disparadores representan un bloque
PL/SQL o un procedimiento PL/SQL asociado
con una tabla, vista, esquema o unabase de
datos.
Disparadores son ejecutados implicitamente
cuando un evento particular toma lugar.
Ing. Diana Cruzado Vásquez
Aplicacion
Pueden ser:
Insert Into Employees
. . .;DISPARADOR DE BASE DE
DATOS(DATABASE TRIGGER)
DISPARADOR DE APLICACIÓN
(APPLICATION TRIGGER)
Se dispara cuando ocurre un
evento con una particular
aplicación.
Se dispara cuando un evento dedatos (tales como DML) o
eventos del sistema (tales como
un logon ”ingreso” o un
shutdown “apagar” ) ocurre
sobre un schema o una base de
datos.
CREATE [OR REPLACE] TRIGGER nombre_disparadorTEMPORIZADOR
EVENTO(S)
ON nombre_tabla
[NIVEL [CONDICION DE DISPARO]]
cuerpo_disparador;
CREATE [OR REPLACE] TRIGGER nombre_disparador
{BEFORE|AFTER|INSTEAD OF}
{[INSERT] [OR UPDATE] [ORDELETE]}
ON nombre_tabla
[REFERENCING OLD AS old AND NEW AS new]
[FOR EACH ROW [WHEN ]]
cuerpo_disparador;
Trigger
Tabla Employees
EMPLOYEE_ID
LAST_NAME
JOB_ID
CHECK_SAL
SALARY
108HERNANDEZ
AD_PRES
3000
109
KARAN
AD_VP
10000
110
MALCA
AD_VP
6000
La sentencia de un disparador DML contiene:
Temporizador:
o Para la tabla: BEFORE, AFTER.
oPara la vista: INSTEAD OF.
Evento: INSERT, UPDATE o DELETE
Nombre de la Tabla: Sobre una Tabla o una Vista.
Nivel: por fila o por sentencia.
Clausula WHEN: Es una condición de restricción. Cuerpo del Trigger (Trigger Body): Es el bloque
PL/SQL.
1
17/07/2012
TEMPORIZADOR
¿ CUANDO SE DEBE DISPARAR UN TRIGGER ?
BEFORE: Ejecuta el cuerpo del disparador antes de
quedispare el evento DML sobre una tabla.
Ejecuta el cuerpo del disparador después
de que dispare el evento DML sobe una tabla.
INSTEAD OF: Ejecuta el cuerpo del disparador en
lugar de la sentencia...
Regístrate para leer el documento completo.