Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent deletion from happening using triggers?

Tags:

sql

oracle

I wish to create a trigger that would PREVENT any deletion on a given table if the day is either sunday or sat AND the time is between 14:00 and 16:00

Currently time is not a big deal, just how can I make the trigger stop the deletion action?

like image 672
Fingolfin Avatar asked Feb 22 '23 00:02

Fingolfin


1 Answers

CREATE OR REPLACE TRIGGER trg_timedelete
   BEFORE DELETE
   ON test

    WHEN (TimeLogicEvaluatesToTrue)
 BEGIN
     raise_application_error (-20100, 'You can not delete at this time');
  END;

The raising of the error will implicitly rollback the transaction and stop the delete.

like image 103
TetonSig Avatar answered Feb 25 '23 05:02

TetonSig