MySQL Forums
Forum List  »  Triggers

Re: Trigger for read-only column
Posted by: Peter Brawley
Date: June 12, 2013 09:25AM

Did you forget to declare a DELIMITER?

IF OLD... is redundant.

Your Trigger doesn't enforce read-only status: it SIGNALs a message then executes the user's update:

drop table if exists t;
create table t(id int, j int);
delimiter go
create trigger idlock before update on t for each row 
  if then signal sqlstate '45000' set message_text = 'cannot update locked record'; 
  end if; 
delimiter ;
insert into t values(null,1);
update t set id=2 where id is null;
select * from t;
| id   | j    |
|    2 |    1 |

Edited 1 time(s). Last edit at 06/15/2013 09:37AM by Peter Brawley.

Options: ReplyQuote

Written By
Re: Trigger for read-only column
June 12, 2013 09:25AM
June 15, 2013 09:46AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.