tags:

views:

39

answers:

2

Context: logging table changes, and we don't want to accidentally mess up the log entries. This is an internal, non-financial app, so we're not worried about hostile modification.

I thought I could just revoke delete/update, but it turns out you can't do that to yourself:

ORA-01749: you may not GRANT/REVOKE privileges to/from yourself

What's the most canonical way to do this?

+1  A: 

Make a BEFORE UPDATE and/or a BEFORE DELETE trigger on the table, which will ALWAYS raise an exception.

Adam Hawkes
-1: triggers can be disabled
Jeffrey Kemp
+3  A: 

You should not use triggers to enforce security requirements.

You should create the table owned by another schema, then only grant the necessary privileges (e.g. INSERT).

Jeffrey Kemp
Now you need another schema for logging. In some cases that is acceptable, but not always.
Adam Hawkes
The standard would be this. The trigger is ok, but I would say this is a better solution. You can even abstract the actual insert through a procedure, and only grant access on the proc, making sure that even inserted records are right+proper.
REW
@Adam, schemas are cheap. I routinely request extra schemas from the DBAs whenever the design calls for them. I can't think of any reason why extra schemas would be a problem for anyone.
Jeffrey Kemp
+1: doing it right.
Vincent Malgrat
I'm not disagreeing with you! I'm just saying that some pointy-haired-bosses demand things like "one-schema-for-one-application" even if that is not the right way. Yes, they're cheap, as are appropriate tables and columns and most other things when done properly. Sometimes the issues are political, not technical.
Adam Hawkes
@Adam - yes, too true, too often, unfortunately...
Jeffrey Kemp