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 8101519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:59:58+00:00 2026-06-05T22:59:58+00:00

I have a Translation table and I want every update to it to automatically

  • 0

I have a Translation table and I want every update to it to automatically be logged in a TranslationHistory table.

I created this trigger for that purpose.

CREATE TRIGGER TranslationUpdate AFTER UPDATE ON Translation FOR EACH ROW BEGIN
   DECLARE N DATETIME;
   DECLARE ActionString VARCHAR(1000);
   SET N = now();
   SET ActionString = '';

   IF NEW.TranslatorID <> OLD.TranslatorID THEN
     SET ActionString = CONCAT(ActionString, 'TranslatorID(', OLD.TranslatorID, ' -> ', NEW.TranslatorID, ') ');
   END IF;

   IF NEW.StartDate <> OLD.StartDate THEN
     SET ActionString = CONCAT(ActionString, 'StartDate(', OLD.StartDate, ' -> ', NEW.StartDate, ') ');
   END IF;

   IF NEW.DueDate <> OLD.DueDate THEN
     SET ActionString = CONCAT(ActionString, 'DueDate(', OLD.DueDate, ' -> ', NEW.DueDate, ') ');
   END IF;

   IF NEW.EndDate <> OLD.EndDate THEN
     SET ActionString = CONCAT(ActionString, 'EndDate(', OLD.EndDate, ' -> ', NEW.EndDate, ') ');
   END IF;

   IF NEW.Notes <> OLD.Notes THEN
     SET ActionString = CONCAT(ActionString, 'Notes(', OLD.Notes, ' -> ', NEW.Notes, ') ');
   END IF;

   INSERT INTO TranslationHistory (TranslationID, Date, Action)
   VALUES (NEW.ID, N, ActionString);
END;

I don’t like it very much because it’s so long, tedious, and repetitious and I’m sure it’s not good SQL. I’d like a DRYer way to do this. Is there a way to do this without having to manually specify details for each column?

  • 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-05T22:59:58+00:00Added an answer on June 5, 2026 at 10:59 pm

    You could wrap each of the code bocks up into a function, but it wouldn’t be much less code in your main procedure than refactoring:

    IF NEW.TranslatorID <> OLD.TranslatorID THEN
        SET ActionString = CONCAT(ActionString, 'TranslatorID(', OLD.TranslatorID, ' -> ', NEW.TranslatorID, ') ');
    END IF;
    

    into this:

    SET ActionString = if(NEW.TranslatorID = OLD.TranslatorID, ActionString, CONCAT(ActionString, 'TranslatorID(', OLD.TranslatorID, ' -> ', NEW.TranslatorID, ') '));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of data for a particular stock that contains every single
I have a table that contains duplicates and uniques id. I want to add
I have a table transaction which has duplicates. i want to keep the record
If I have a table structure like this: Transaction [TransID, ...] Document [DocID, TransID,
I have a declarative table defined like this: class Transaction(Base): __tablename__ = transactions id
i need to update a database where some of the table have changed (columns
I have innoDB table using numerous foreign keys, but we just want to look
(Note: this is for MS SQL Server) Say you have a table ABC with
I have a table that contains procedure codes among other data (let's call it
I've got a scenario where I have a database with one table that gets

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.