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.
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.
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.