how to get last modified column name from mysql -


is possible particular updated column name record?

if so, please me. since creating history table store updated column , values rest of tables.

drop trigger if exists testing.hisupdate;   create trigger testing.hisupdate after update on testing.emp each row insert testing.history (`id`,`revision_id`,`trx_code`, `trx_method`, `column_name`, `old_value`, `new_value`, `trx_timestamp`, `user_id`) select   (select emp_id    testing.emp    order last_update desc limit 1),   (select p.revision_id    testing.history p    p.id=        (select emp_id         testing.emp         order last_update desc limit 1)    order trx_timestamp desc limit 1) + 1, 'updt', 'update','null',   (select p.new_value    testing.history p    p.id=        (select emp_id         testing.emp         order last_update desc limit 1)    order trx_timestamp desc limit 1), concat(p.emp_id,"/",p.emp_name,"/",p.salary,"/") new_value,                                          now(),                                          '101' testing.emp p p.emp_id = new.emp_id; 

i have created trigger searching sub query last updated column name.. in advance.

try code...

create table sales(orderno int, sale int,empsalary int, ts timestamp);  create table history(updated varchar(20), oldvalue int,newvalue int);  insert sales (orderno,sale,empsalary) values(1,700,7000);  insert sales (orderno,sale,empsalary) values(2,800,8000);  insert sales (orderno,sale,empsalary) values(3,900,9000);  drop trigger test.instrigger; 

delimiter ///

create trigger test.instrigger after update on sales each row  begin      if new.sale <> old.sale           insert history (updated, oldvalue, newvalue) values('sale', old.sale,new.sale);      end if;     if new.empsalary <> old.empsalary           insert history (updated, oldvalue, newvalue) values('empsalary', old.empsalary,new.empsalary);     end if; end; 

///

delimiter ;


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -