Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

Trigger Update not working if starts null

If got a simple trigger which is to update a log table (which I unfortunately need), however if the value of `phoneNumber` is its default of Null, when I update it like:-
UPDATE `contract` SET `phoneNumber` = '44464' WHERE `contract`.`priID` = 8;

Open in new window

I dont get a line in the logger, however if I execute again differently so the so OLD.`phoneNumber` isnt null then trigger fires fine and runs the insert command.

My trigger code is:-
Begin
IF OLD.`phoneNumber` <> NEW.`phoneNumber` THEN
             INSERT INTO `mobilephones`.`_logger` (`dateTime`, `connectionID`, `table`, `priID`, `feild`, `newValue`,`action`) VALUES (NOW(), CONNECTION_ID(), 'contract', NEW.`priID`, 'phoneNumber', NEW.`phoneNumber`, 'Update');
END IF; 
End

Open in new window


Any ideas what Im doing wrong?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial