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

  • SEARCH
  • Home
  • 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 9168253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:35:09+00:00 2026-06-17T15:35:09+00:00

I have a trigger in MySQL table. Table has about 20 columns. DELIMITER $$

  • 0

I have a trigger in MySQL table. Table has about 20 columns.

DELIMITER $$
CREATE
DEFINER=`root`@`localhost`
TRIGGER `completion_date_update`
BEFORE UPDATE ON `orders`
FOR EACH ROW
BEGIN
  IF NEW.`order_status` = 'COMPLETED' THEN
    SET NEW.`completion_date` = NOW();
  END IF;

  IF NEW.`order_status` != 'COMPLETED' THEN
    SET NEW.`completion_date` = NULL;
  END IF;
END$$

What I want is this trigger to update completion_date column only when column order_status is updated. If any other column is updated this trigger should not do anything.
What is actually happening is this trigger is updating completion_date upon any column update.

Can anyone explain to me why does this happen and what did I do wrong?

order_status column is NOT NULL and has possible values as below:

enum('NEW','OPEN','COMPLETED','CANCELLED','REPLACED')

Default is 'NEW'

Thanks

  • 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-17T15:35:10+00:00Added an answer on June 17, 2026 at 3:35 pm

    you should also compare if order_status has been changed and that the new value is COMPLETED

    IF (NEW.order_status <> OLD.order_status) AND (NEW.order_status = 'COMPLETED') THEN 
        SET NEW.completion_date = NOW();
    END IF;
    

    and you can remove the other IF below.

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

Sidebar

Related Questions

I have a BEFORE UPDATE trigger on one table. Now in that trigger, I
Here is the MYSQL Trigger that I have written: DELIMITER // CREATE TRIGGER updtrigger
I have a trigger that check data before insert to another table IF NOT
is is possible in postgres to have a trigger on CREATE TABLE that will
I'm having some problems with mySQL triggers. I have this working: CREATE TRIGGER `insert_trigger`
I'm trying to create a trigger in phpMyadmin (MySQL) I have two tables, members
I have two tables, round and event. One round has many events. create table
I want to create a MySQL trigger that updates a table everytime one of
I have a table in mysql: ( _table ) with a a few columns,
I have a mysql table called books that has a votes column, and another

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.