MySQL Trigger for data audit

Hello,

I am using mysql trigger but i saw a problem
Mysql trigger doesn’t work if column default is NULL and data is updated to row.
But when the column is set to default NONE, the Mysql trigger works when data is updated to the row.

Is this the rule or is there something to be done?

  `tarih` varchar(20) DEFAULT NULL,
    

IF OLD.tarih <> new.tarih THEN
        insert into product_audit_trail(product_id, serial_number, product_code, column_name, old_value, new_value, islem, islemi_yapan) values(NEW.product_id,NEW.serial_number,NEW.product_code,'tarih',OLD.tarih,NEW.tarih,NEW.islem,NEW.islemi_yapan);
    END IF;

I found a solution like below, but I don’t know how true it is

IF OLD.tarih <> new.tarih THEN
	insert into product_audit_trail(product_id, serial_number, product_code, column_name, old_value, new_value, islem, islemi_yapan) values(NEW.product_id,NEW.serial_number,NEW.product_code,'tarih',OLD.tarih,NEW.tarih,NEW.islem,NEW.islemi_yapan);
END IF;
IF OLD.tarih IS NULL THEN
	insert into product_audit_trail(product_id, serial_number, product_code, column_name, old_value, new_value, islem, islemi_yapan) values(NEW.product_id,NEW.serial_number,NEW.product_code,'tarih',OLD.tarih,NEW.tarih,NEW.islem,NEW.islemi_yapan);
END IF;
IF New.tarih IS NULL THEN
	insert into product_audit_trail(product_id, serial_number, product_code, column_name, old_value, new_value, islem, islemi_yapan) values(NEW.product_id,NEW.serial_number,NEW.product_code,'tarih',OLD.tarih,NEW.tarih,NEW.islem,NEW.islemi_yapan);
END IF;
Sponsor our Newsletter | Privacy Policy | Terms of Service