MYSQL AFTER Trigger UPDATE IF -
i want update row after has been updated user. example if after user selects 32, , principal entered > 1000. update 32 40.
create trigger updateusers_id after update on table each row begin if(new.users_id = 32 , table.principal > 50000) update loans set users_id = 40; end if; end
think second , you'll realize first problem: if need here after
update trigger... before
update trigger do?
after update
means after update query has changed row data. looking before update
-- want hijack update in mid-stream, before table data gets changed, , potentially modify values written database.
update loans set users_id = 40;
there 2 problems this. first, know update
without where
does... right? updates all rows in table. luckily, server didn't let that. solution not add where
clause -- it's this:
if(new.users_id = 32 , new.principal > 50000) set new.users_id = 40; end if;
the new
pseudotable contains row data user has tried cause update
(that fired trigger) write row. in before update ... each row
trigger, setting new
values overrides user tried do... appears wanting accomplish.
Comments
Post a Comment