Use Oracle and Triggers to Secure Table Data

Use Oracle and Triggers to Secure Table Data

Ever deleted some tables accidently and had to waste your time doing them all over again? Oracle, in conjunciton with Triggers, provides an easy solution to this problem.

First, create a table that holds the table name. Say you create a table called SafeTable with a column names SafeTableName and the datatype varchar2. Populate this table with the table names that should not be dropped. Then go ahead and create the trigger as follows:

CREATE or REPLACE TRIGGER checkForSafeTable BEFORE DROP ON DATABASEDECLARE  TABLENAME CHAR(20);BEGIN  SELECT SafeTableName INOT TABLENAME from SafeTable   WHERE UPPER(TABLENAME)=ora_dict_obj_name;  IF sql%found THEN    RAISE_APPLICATION_ERROR(-20001,'This is a SAFE table');  END IF;EXCEPTION  WHEN no_data_found   THEN dbms_output.put_line('This table will be dropped');END;

When you create this trigger, you cannot drop any table that has an entry in the SafeTable.

See also  10 Best Apps to Help You Read More Books in Less Time

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist