Saturday, October 31, 2009

Bypass the ON UPDATE trigger in mysql

Recently at work, I came across a problem where I had to bypass the ON UPDATE trigger for a particular table. I dint want this to happen as I was making manual updates on the backend and dint want the change to get reflected on the UI. To prevent this, you could add the column in the UPDATE clause (even though it doesnt have to change). Something like
   CREATE TABLE  test (
         id integer not null auto_increment,
         name varchar(20) not null,
         upd_date datetime default current_timestamp on update current_timestamp

If I just do a
      UPDATE test set name = 'raja' where id = 2;
that would update the upd_date column as well. IF I want to avoid the upd_date column from getting updated, you could do a
      UPDATE test set name = 'raja', upd_date = upd_date where id = 2;

No comments:

Post a Comment