mysql - Make Rows Immutable and allow insert -


i want make rows in mysql table immutable, once inserted don't want possible change them. how can this?

(ideally returning suitable error message if change attempted).

i dont have grant privileges, understand how write before update trigger raises error (using signals or issuing statement fails). use mysql5.

a simple trigger should it;

create trigger stop_update before update on table1 each row   signal sqlstate '45000' set message_text = 'update not allowed!' // 

an sqlfiddle test with. can add update test.

of course, may want same delete.

edit: if you're using lower mysql version 5.5 added signal, can limit write (not quite cleanly) intentionally causing error instead;

create trigger stop_update before update on table1 each row   update update_of_table1_is_not_allowed set value='update not allowed!' // 

another sqlfiddle. can't add errors in ddl , have sqlfiddle save it, changing updated id 1 (an existing row) in left window fail update.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -