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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:47:01+00:00 2026-06-07T00:47:01+00:00

I want to run an update query. The query will be run against multiple

  • 0

I want to run an update query.

The query will be run against multiple databases – not every database will have the table.

I don’t want the update to be attempted if the table does not exist. I don’t want any error to be thrown – I just want the update to be ignored.

Any ideas?

EDIT: just to be clear – the query is executed in an automated deployment – no human interaction possible.

EDIT2: the logic to say whether the update should run or not will need to be in the MySql query itself. This is not being run through a command prompt or batch or managed code.

  • 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-07T00:47:02+00:00Added an answer on June 7, 2026 at 12:47 am

    To do this in native MySQL (like in a mysql script), you could use a stored procedure.

    This would be appropriate for a one-off administrative type function, you wouldn’t want to do this as part of an application. (Then again, if this were part of an application, you would have the conditional logic to control whether an UPDATE is performed, or to catch and handle the exception if the table doesn’t exist.)

    Here’s an example of a stored procedure that uses a CONTINUE HANDLER to catch error 1146 (table does not exist) and swallow it, so that no error is returned to the caller.


    DELIMITER //
    DROP PROCEDURE IF EXISTS `table_doesnt_exist_handler`//
    CREATE DEFINER=`root`@`%` PROCEDURE `table_doesnt_exist_handler`()
    BEGIN
      DECLARE table_doesnt_exist BOOLEAN;
      DECLARE CONTINUE HANDLER FOR 1146 SET table_doesnt_exist = TRUE;
    
      UPDATE table_doesnt_exist SET foo = 1 WHERE foo = 1;
    
    END//
    CALL `table_doesnt_exist_handler`()//
    DROP PROCEDURE IF EXISTS `table_doesnt_exist_handler`//
    DELIMITER ;
    

    Another option is to test for the existence of the table, and conditionally running the statement. In native MySQL, again, this would need to be done inside a stored procedure.

    DELIMITER //
    DROP PROCEDURE IF EXISTS `table_doesnt_exist_approach_2`//
    CREATE DEFINER=`root`@`%` PROCEDURE `table_doesnt_exist_approach_2`()
    BEGIN
      SELECT @table_exists := COUNT(1) AS table_exists
        FROM information_schema.tables
       WHERE table_schema = DATABASE() 
         AND table_name = 'table_doesnt_exist';
      IF  @table_exists > 0 THEN
        UPDATE table_doesnt_exist SET foo = 2 WHERE foo = 1;
      END IF;
    END//
    
    CALL `table_doesnt_exist_approach_2`()//
    DROP PROCEDURE IF EXISTS `table_doesnt_exist_approach_2`//
    DELIMITER ;
    

    My preference would be to go with the CONTINUE HANDLER.

    • 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 postcodes and I want to update each postcode with
Why this code don't work,when i want run this code vwd 2008 express show
I have written php program and uploaded on server. I want run this program
Want to run javascript function from parent window in child window Example I have
I want to have multiple scripts running from cron at the same time. They
I have the following schema: Database: test. Table: per_login_user, Field: username (PK), password Database:
I'm trying to run a report on our database. We want to know the
I have two databases: old and new. Both have a comments table. There are
Often I want to add a value to a table or update the value
i have a table with the fields : [VARIABLE_CODE],[VARIABLE_NAME],[CAS_NO],[USER_VAR_GROUP_NAME] and what i want to

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.