Re: Trigger for read-only column
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.
Subject
Views
Written By
Posted
2958
June 12, 2013 07:53AM
Re: Trigger for read-only column
1804
June 12, 2013 09:25AM
4347
June 12, 2013 01:57PM
1708
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.