database/oracle

DDL Trigger

labj 2012. 3. 22. 00:16

- create, alter, drop 행위를 추적하는 Trigger를 만듬

 

CREATE OR REPLACE TRIGGER audit_object_create AFTER CREATE ON SCHEMA -- 현재 내 SCHEMA 안에서만 추적하라 ( 전체라면 DATABASE로 )
BEGIN
 INSERT INTO trigger_log
 VALUES ('CREATE ' || sys.dictionary_obj_type || ' ' || sys.dictionary_obj_name || ' by ' || sys.login_user, sysdate);
END;

 

 

CREATE OR REPLACE TRIGGER audit_object_alter AFTER ALTER ON SCHEMA
BEGIN
 INSERT INTO trigger_log
 VALUES ('ALTER ' || sys.dictionary_obj_type || ' ' || sys.dictionary_obj_name || ' by ' || sys.login_user, sysdate);
END;

 

 

CREATE OR REPLACE TRIGGER audit_object_drop AFTER DROP ON SCHEMA
BEGIN
 INSERT INTO trigger_log
 VALUES ('DROP ' || sys.dictionary_obj_type || ' ' || sys.dictionary_obj_name || ' by ' || sys.login_user, sysdate);
END;

 

 

 

 

 

 

 

 

CREATE TABLE test(a char);

 

select * from trigger_log;
 

 

 

ALTER TABLE test MODIFY a char(2);

 

select log, to_char(timestamp, 'YYYY-MM-DD HH24:MI:SS')
FROM trigger_log ORDER BY timestamp DESC;
 

 


drop table test;

 

select log, to_char(timestamp, 'YYYY-MM-DD HH24:MI:SS')
FROM trigger_log ORDER BY timestamp DESC;

 

 

'database > oracle' 카테고리의 다른 글

Procedure, Function & Package 개념  (0) 2012.03.22
Database Event Trigger  (0) 2012.03.22
INSTEAD OF Trigger  (0) 2012.03.22
Synonym  (0) 2012.03.22
Sequence  (0) 2012.03.22