Upload
erika-contreras-huamani
View
221
Download
0
Embed Size (px)
Citation preview
7/25/2019 Auditoria con triggers.pdf
1/7
7/25/2019 Auditoria con triggers.pdf
2/7
UNIVERSIDAD NACIONAL DE SAN CRISTOBAL DE HUAMANGAFACULTAD DE ING. MINAS, GELOGIA Y CIVIL
ESCUELA DE FORMACIN PROFESIONAL DE INGENIERIA DE SISTEMAS
Lab. Administracin de Base de Datos 2 Prof. Elvira Fernndez(IS-443)
Con estos predicados podemos crear un solo desencadenador para doso las tres instrucciones que lo generan.
Insert Update Delete
Ejemplo 01:Las siguientes instrucciones crean un desencadenador llamadostr_stock que se ejecuta cuando se utiliza la instruccin insert, deleteo update en la tabla producto.
Ojo: si creo anteriormente estos desencadenadores por separado, estedesencadenador reemplaza a los tres desencadenadores creados y porello deber eliminarlos previamente.
7/25/2019 Auditoria con triggers.pdf
3/7
UNIVERSIDAD NACIONAL DE SAN CRISTOBAL DE HUAMANGAFACULTAD DE ING. MINAS, GELOGIA Y CIVIL
ESCUELA DE FORMACIN PROFESIONAL DE INGENIERIA DE SISTEMAS
Lab. Administracin de Base de Datos 3 Prof. Elvira Fernndez(IS-443)
EJERCICIO 01VERIFIQUE y MUESTRE LOS RESULTADOS(ANTES Y DESPUES DEAPLICAR LOS EVENTOS) PARA CADA EVENTO(INSERT, UPDATE YDELETE), MOSTRAR LOS RESULTADOS OBTENIDOS.
Ejemplo02:Conectarse como usuario hr y crear un triggers donde se restringe lainsercin dentro de la tabla employees en ciertas horas de trabajo yde lunes a viernes.
7/25/2019 Auditoria con triggers.pdf
4/7
UNIVERSIDAD NACIONAL DE SAN CRISTOBAL DE HUAMANGAFACULTAD DE ING. MINAS, GELOGIA Y CIVIL
ESCUELA DE FORMACIN PROFESIONAL DE INGENIERIA DE SISTEMAS
Lab. Administracin de Base de Datos 4 Prof. Elvira Fernndez(IS-443)
VERIFICAMOS LA CREACION DEL TRIGGERTR_SEGURIDAD_EMPLEADOS POR MEDIO DE LA VISTAUSER_TRIGGERS.
SELECT SUBSTR(TRIGGER_NAME, 1,25)TRIGGER_NAME,TRIGGER_TYPE, TABLE_NAME,STATUSFROM USER_TRIGGERS;
PROBAR DESENCADENANTE
Ejercicio2: En la sesin hr intentar insertar datos en la tablaemployees, para que se dispare el trigger.
Ejemplo03:Crear las tablas rdenes y su respectiva tabla de auditora.
Create table orden(Order_id number(5),Cantidad number(4),
Costo_unitario number(6,2),
7/25/2019 Auditoria con triggers.pdf
5/7
UNIVERSIDAD NACIONAL DE SAN CRISTOBAL DE HUAMANGAFACULTAD DE ING. MINAS, GELOGIA Y CIVIL
ESCUELA DE FORMACIN PROFESIONAL DE INGENIERIA DE SISTEMAS
Lab. Administracin de Base de Datos 5 Prof. Elvira Fernndez(IS-443)
Total_costo number(8,2));
Create table orden_auditoria(Order_id number(5),
Cantidad number(4),Costo_unitario number(6,2),Total_costo number(8,2),User_auditoria varchar(25));
Construir un trigger que capture qu usuario ha insertado nuevasrdenes:
EJERCICIO3:inserte un registro en la tabla orden y verifique los resultados.
EJERCICIO04:modifique el ejemplo03, para que el desencadenante muestre un
mensaje acaba de ingresar nuevo registro en la tabla orden, el usuario x.
7/25/2019 Auditoria con triggers.pdf
6/7
UNIVERSIDAD NACIONAL DE SAN CRISTOBAL DE HUAMANGAFACULTAD DE ING. MINAS, GELOGIA Y CIVIL
ESCUELA DE FORMACIN PROFESIONAL DE INGENIERIA DE SISTEMAS
Lab. Administracin de Base de Datos 6 Prof. Elvira Fernndez(IS-443)
EJEMPLO 04Tambin puedes crear UN DESENCADENANTE que guarde todo el registro:
CREATE TABLE TABLA_A_AUDITAR(
AUD_USER VARCHAR2(25),AUD_FECHA DATE,
AUD_TIPO VARCHAR(25),
AUD_TERMINAL VARCHAR(25)
)
Ejercicio05: insertar registro tabla empleados.
ANEXO
Formato funcin Date
Parameter Explanation
YEAR Year, spelled out
YYYY 4-digit year
YYYYYY
Last 3, 2, or 1 digit(s) of year.
IYYIYI
Last 3, 2, or 1 digit(s) of ISO year.
IYYY 4-digit year based on the ISO standard
Q Quarter of year (1, 2, 3, 4; JAN-MAR = 1).
MM Month (01-12; JAN = 01).
7/25/2019 Auditoria con triggers.pdf
7/7
UNIVERSIDAD NACIONAL DE SAN CRISTOBAL DE HUAMANGAFACULTAD DE ING. MINAS, GELOGIA Y CIVIL
ESCUELA DE FORMACIN PROFESIONAL DE INGENIERIA DE SISTEMAS
Lab. Administracin de Base de Datos 7 Prof. Elvira Fernndez(IS-443)
Parameter Explanation
MON Abbreviated name of month.
MONTH Name of month, padded with blanks to length of 9 characters.
RM Roman numeral month (I-XII; JAN = I).
WWWeek of year (1-53) where week 1 starts on the first day of the yearand continues to the seventh day of the year.
WWeek of month (1-5) where week 1 starts on the first day of themonth and ends on the seventh.
IW Week of year (1-52 or 1-53) based on the ISO standard.
D Day of week (1-7).
DAY Name of day.
DD Day of month (1-31).
DDD Day of year (1-366).
DY Abbreviated name of day.
J Julian day; the number of days since January 1, 4712 BC.
HH Hour of day (1-12).
HH12 Hour of day (1-12).
HH24 Hour of day (0-23).
MI Minute (0-59).
SS Second (0-59).
SSSSS Seconds past midnight (0-86399).
FF Fractional seconds.