TRIGGER to prevent deleting record with a specific identifier

1

I'm doing a job with PL / SQL, oracle and sqldeveloper and I have a table to which I want to create a trigger that prevents me from deleting a record that has an id in the field 1. I do not know how to do it.

    
asked by Javi Palacios 19.05.2016 в 22:54
source

1 answer

0

You can achieve this with a trigger BEFORE DELETE in the following way

CREATE OR REPLACE TRIGGER BEFORE_DEL_TRIG
   BEFORE DELETE ON tabla
FOR EACH ROW
BEGIN
   If :Old.id = 1 then
   Raise_Application_Error(-20099, 'Cannot delete this record.');
End If;
END;
/

The trigger checks the value of the column that you specify and throws an error in case the condition is fulfilled.

    
answered by 20.05.2016 / 00:32
source