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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:40:03+00:00 2026-05-18T05:40:03+00:00

I have a MySQL database that contains many tables, some of them created dynamically

  • 0

I have a MySQL database that contains many tables, some of them created dynamically by the software. The dynamic tables have a consistent naming scheme:

dynamic_1  
dynamic_2  
...

However, I don’t necessarily know how many of these tables there are.

I’d like to be able to delete all of these dynamic tables without dropping the entire database. I’d like to be able to do this purely in SQL. (Stored procedures are ok.) Is this is even possible?


Quick addendum.

The solution from Haim and Alexandre works great, but there’s one special case we all missed. What if there are -no- dynamic tables? In that case @v will be NULL and we get an error when we try to execute. I added a second variable to handle this case:

SET @v = (SELECT CONCAT('drop table ', GROUP_CONCAT(a.table_name)) FROM information_schema.tables a where a.table_schema = DATABASE() AND a.table_name like 'dynamic_%');
SET @y = (SELECT IF (@V IS NOT NULL, @V, 'select 1'));
PREPARE s FROM @y;
EXECUTE s; 
  • 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-18T05:40:04+00:00Added an answer on May 18, 2026 at 5:40 am

    you can run this query and get all the sql queries that you need to run;

    select concat( 'drop table ', a.table_name, ';' )
    from information_schema.tables a 
    where a.table_name like 'dynamic_%';
    

    you can insert it to file like

    INTO OUTFILE '/tmp/delete.sql';
    

    update according to alexandre comment

    SET @v = ( select concat( 'drop table ', group_concat(a.table_name))
        from information_schema.tables a 
        where a.table_name like 'dynamic_%'
        AND a.table_schema = DATABASE()
    ;);
     PREPARE s FROM @v; 
    EXECUTE s;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 'price' variable that contains some integer number from a MySQL database.
I ran into an interesting problem. I have a MySQL database that contains some
I have 50GB mysql database (80 tables) that I need to delete some contents
The code below works great. I have a MySQL database that contains book titles
I'm trying to normalize a mysql database.... I currently have a table that contains
I have a mysql database that looks like this: |id | city | created
I have a mysql database that contains snippets of latex code, identified by a
I have this MySQl database that has a table which contains a column that
I have a mysql database which contains several tables. At the moment i'm using
I have some software that is heavily dependent on MySQL, and is written in

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.