Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

How to DROP several TABLES with a wildcard?

Hi,

I have a lot of tables in my DB that I want to delete. They all start with 'temp'.

How can I delete all of them at once?

3 Answers

Andrew McCormick
Andrew McCormick
17,730 Points

maybe: DROP table WHERE table LIKE "temp%' ;

No, that doesn't work.

I am doing the Deep Dive "Database Foundations" with Andrew Chalkley (who is a great and funny tutor) but I haven't found a solution there. May anybody give me a hint?

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Fabian Raschke

I looked in the documentation and it doesn't look like it's possible.

You could use another programming language to do SHOW tables where Tables_in_<database_name_here> LIKE 'temp%' and then cycle over them and drop each one.

Hope that helps.
Andrew