Solved

Trigger Update not working if starts null

Posted on 2014-09-30
1
206 Views
Last Modified: 2014-10-17
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?
0
Comment
Question by:tonelm54
1 Comment
 
LVL 52

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 40353211
The article below might shed some light

http://coldfusionbeyond.com/post.cfm/mysql-trigger-flakiness-and-null-in-comparisons

Basically saying that comparing null to null gives null and not 1 (equal).

Not sure if the suggested work around can help but it might give some insight.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now