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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:10:27+00:00 2026-05-25T19:10:27+00:00

Is it possible to build a stored procedure that creates a trigger in MySQL?

  • 0

Is it possible to build a stored procedure that creates a trigger in MySQL?
I have the stored proc below, which works fine, but it only outputs the code to create the trigger, but does not actually create it.

DELIMITER $
CREATE PROCEDURE addCustomerLogTrigger()
BEGIN
    SELECT CONCAT(
        'CREATE TRIGGER customer_audit AFTER UPDATE ON customer FOR EACH ROW BEGIN ',
        GROUP_CONCAT(
            CONCAT(
                'IF OLD.', column_name, ' != NEW.', column_name, ' THEN INSERT INTO st_person_audit_log (',
                    'id, ',
                    'fieldName, ',
                    'old_value, ',
                    'new_value, ',
                    'time_stamp, ',
                    'person_id'
                    ') VALUES (
                    NEW.id,
                    ''', column_name, ''', 
                    OLD.', column_name, ',
                    NEW.', column_name, ',
                    NOW(),
                    NEW.last_updated_by
                ); END IF;'
            )
            SEPARATOR ' '
            ), ' END;$'
        )
        FROM
            information_schema.columns
        WHERE
            table_schema = database()
            AND table_name = 'customer';

END$
DELIMITER ;

Is there a way to create it in one go?
I got it from http://thenoyes.com/littlenoise/?p=43 and adjusted it a little to my needs.

Just FYI, this trigger inserts a old/new value pair into an audit table, whenever something changes in the customer table.

  • 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-05-25T19:10:27+00:00Added an answer on May 25, 2026 at 7:10 pm

    No, it is not possible, even with MySQL prepared statements.

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

Sidebar

Related Questions

I have a provided stored procedure (SP) that i should execute in tibco, which
I was wondering if it is possible in a mysql stored-function or stored-procedure compose
I have written a CLR stored procedure that is in an assembly. I have
If I have 6 modules in my project is it possible to build only
Given this MySQL stored procedure: CREATE PROCEDURE customer.`getCustomers5`( sdf varchar(1000) ) BEGIN set @se
Is it possible to have your parameter files for msdeploy stored and accessed from
I have a trigger that gets inserts and updates to a view. I need
I have be asked to build a site that is to be built in
I have been asked to build a rather simple form processor application that interacts
I have to build (obviously using flex) an AIR application that must be linked

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.