delimiter $$

use `makmosco_jacob`$$

drop trigger /*!50032 IF EXISTS */ `tg_rast_prod_up`$$

create
    /*!50017 DEFINER = 'makmosco_jacobadmin'@'%' */
    trigger `tg_rast_prod_up` after update on `rast_prod` 
    for each row begin

		if new.idequip_rast_prod <> old.idequip_rast_prod then
			call sp_auditoria(		
				new.idmodificacao_rast_prod,
				old.idmodificacao_rast_prod,
				new.id_rast_prod,
				'rast_prod',
				'idequip_rast_prod',
				old.idequip_rast_prod,
				new.idequip_rast_prod		
			);
		end if;
		
		if new.tipo_rast_prod <> old.tipo_rast_prod then
			call sp_auditoria(		
				new.idmodificacao_rast_prod,
				old.idmodificacao_rast_prod,
				new.id_rast_prod,
				'rast_prod',
				'tipo_rast_prod',
				old.tipo_rast_prod,
				new.tipo_rast_prod		
			);
		end if;
		
		if new.desc_rast_prod <> old.desc_rast_prod then
			call sp_auditoria(		
				new.idmodificacao_rast_prod,
				old.idmodificacao_rast_prod,
				new.id_rast_prod,
				'rast_prod',
				'desc_rast_prod',
				old.desc_rast_prod,
				new.desc_rast_prod		
			);
		end if;
		
		if new.venc_rast_prod <> old.venc_rast_prod then
			call sp_auditoria(		
				new.idmodificacao_rast_prod,
				old.idmodificacao_rast_prod,
				new.id_rast_prod,
				'rast_prod',
				'venc_rast_prod',
				old.venc_rast_prod,
				new.venc_rast_prod		
			);
		end if;
		
		if new.valor_rast_prod <> old.valor_rast_prod then
			call sp_auditoria(		
				new.idmodificacao_rast_prod,
				old.idmodificacao_rast_prod,
				new.id_rast_prod,
				'rast_prod',
				'valor_rast_prod',
				old.valor_rast_prod,
				new.valor_rast_prod		
			);
		end if;
		
		if new.plano_rast_prod <> old.plano_rast_prod then
			call sp_auditoria(		
				new.idmodificacao_rast_prod,
				old.idmodificacao_rast_prod,
				new.id_rast_prod,
				'rast_prod',
				'plano_rast_prod',
				old.plano_rast_prod,
				new.plano_rast_prod		
			);
		end if;
		
		if new.obs_rast_prod <> old.obs_rast_prod then
			call sp_auditoria(		
				new.idmodificacao_rast_prod,
				old.idmodificacao_rast_prod,
				new.id_rast_prod,
				'rast_prod',
				'obs_rast_prod',
				old.obs_rast_prod,
				new.obs_rast_prod		
			);
		end if;

    end;
$$

delimiter ;