IMHO the database would be the best place for this logic since the data is then safe regardless what application tries to modify the data.
In order to do that, I'd write a TRIGGER for DELETE and check if the row being deleted shouldn't be allowed to. In such case I'd raise an error.
For more information, see
13.1.11 CREATE TRIGGER Syntax[
^]