Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8276143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:17:29+00:00 2026-06-08T08:17:29+00:00

Here is the MYSQL Trigger that I have written: DELIMITER // CREATE TRIGGER updtrigger

  • 0

Here is the MYSQL Trigger that I have written:

DELIMITER //
CREATE TRIGGER updtrigger BEFORE UPDATE ON myTable
    FOR EACH ROW
    BEGIN
    IF (OLD.column IS NOT NULL AND NEW.column IS NOT NULL AND NEW.column != OLD.column) THEN 
        SET NEW.col_updated_on = NOW();
    END IF;
END //
DELIMITER ;

If column has a value (say, “movie”), and I update it to get new value, “movie,music”, the trigger gets executed and col_updated_on should have the current timestamp.

However, when column is NULL and I update it to get the new value, “movie”, the col_updated_on column will still show me the old timestamp.

Please let me know what change I must do to check for this condition as well.

Thanks in advance for your replies.

I have another question. Is the below pseudo possible??

Here are my two tables –
myTable(id, someId, col_updated_on);
myOtherTable(id, col1, col2);

myTable.someId has a 1-on-1 relation with myOtherTable.id

I want to update myTable.col_updated_on whenever myOtherTable.col1 and myOtherTable.col2 are updated. How do i do this? and should i use “BEFORE UPDATE” or “AFTER UPDATE”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:17:33+00:00Added an answer on June 8, 2026 at 8:17 am

    Use the NULL-safe equality operator:

    IF NOT OLD.column <=> NEW.column THEN
    

    However, note that MySQL’s TIMESTAMP data type can (and, by default, will) automatically update whenever a record is updated, making such a trigger unnecessary.

    But also, you REALLY shouldn’t store multiple items in a delimited string in a relational database like MySQL. Read up on database design, especially one-to-many relationships: one would fare much better by having a separate table, in which each record links an identifier (key) from your existing (foreign) table to a single item; one would then join the tables together as required in your queries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an update trigger in MySQL Community Server 5.5.16 but
I have some stored procedures and a trigger that work great in MySQL 5.5.8
I'm creating a trigger in MySQL but have a slight issue. Here's the trigger
I tried writing this small trigger in MySQL, CREATE TRIGGER `leg` BEFORE INSERT ON
This question here: MySQL: INSERT IGNORE or ON DUPLICATE KEY UPDATE with checking multiple
Here is my MySQL Query that im trying to execute. it keeps failing with
here is my mysql and php code layout: I have 3 tables tableA stores
I am trying to set up a MySQL trigger that does the following: When
I am trying to create some MySQL code that will invoke a Java program
Can someone please help me with MySQL Trigger Lets say I have two Tables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.