MySQL Forums
Forum List  »  Triggers

Re: Trigger for read-only column
Posted by: Fitsum Tesfagiorgis
Date: June 12, 2013 01:57PM

Thanks Peter it's working now! But I can not update any of the fields. I want only the client_id to be locked.

mysql> delimiter //
mysql> CREATE TRIGGER client_id_lock BEFORE UPDATE ON users_column_lock
-> FOR EACH ROW
-> BEGIN
-> IF OLD.client_id THEN SIGNAL SQLSTATE '45000'
-> SET
-> MESSAGE_TEXT = 'Cannot update locked record';
-> END IF;
-> END;//
Query OK, 0 rows affected (0.11 sec)

update users_column_lock set client_id=20 where users_id=521;
ERROR 1644 (45000): Cannot update locked record

mysql> update users_column_lock set first_name='Fitsum' where users_id=521;
ERROR 1644 (45000): Cannot update locked record



Edited 2 time(s). Last edit at 06/12/2013 02:25PM by Fitsum Tesfagiorgis.

Options: ReplyQuote


Subject
Views
Written By
Posted
1718
June 12, 2013 09:25AM
Re: Trigger for read-only column
4220
June 12, 2013 01:57PM
1637
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.