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 
begin 
  if old.id then signal sqlstate '45000' set message_text = 'cannot update locked record'; 
  end if; 
end; 
go
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


Subject
Views
Written By
Posted
Re: Trigger for read-only column
1592
June 12, 2013 09:25AM
1501
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.