5-10. Triggering on a Schema-Related Event

Problem

You want to trigger on an event related to a change in a database schema. For example, if someone drops a database table on accident, it could cause much time and grief attempting to restore and recover data to its original state. Rather than doing so, you want to place a control mechanism into the database that will ensure that administrators cannot delete essential tables.

Solution

Use a PL/SQL database trigger to raise an exception and send an alert to the DBA if someone attempts to drop a table. This will prevent any tables from inadvertently being dropped, and it will also allow the administrator to know whether someone is potentially trying to drop tables.

CREATE OR REPLACE TRIGGER ddl_trigger ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.