在oracle系统中,若DBA权限一旦控制不好,则有可能造成表及数据的误删除,
如用户原希望删除A表,如 Trop table A cascade constraints;
结果由于输入错误,将语句变为 Trop table B cascadeconstraints; 则会造成误删B 表。
有时用户还可能误发出Truncate Table 命令,造成数据库数据表的数据清除。利用数据库系统触发器,可以避免发生类似操作。
Oracle10g环境下,利用SYS用户登录,使用如下脚本建立系统触发器TRIGGER_UNDROPTABLE:
CREATEOR REPLACE TRIGGER TRIGGER_UNDROPTABLE
BEFORE DROP or TRUNCATE ON DATABASE
begin
if ora_login_user not in ('SYS') THEN
if upper(dictionary_obj_type) ='TABLE'or upper(dictionary_obj_type)='INDEX' THEN
Raise_application_error (-20001,'Please not do DROPTable or Index,do not Truncate table ,You will be Caught!!!');
end if;
end if;
end;
/
Oracle817环境下,由于没有TRUNCATE系统触发器,无法在整个系统内防止truncate table操作,只能对特定的表进行处理,但仍可以利用触发器防止数据库表误删除,如以下脚本:
CREATEOR REPLACE TRIGGER TRIGGER_UNDROPTABLE
BEFORE DROP ON DATABASE
begin
if ora_login_user not in ('SYS','SYSTEM') THEN
if upper(dictionary_obj_type) ='TABLE'or upper(dictionary_obj_type)='INDEX' THEN
Raise_application_error (-20001,'Please not do DROPTable or Index ,You will be caught!!!');
end if;
end if;
end;
/