views:

40

answers:

2

Alright, I'm trying to write a piece of code (PHP and SQL), or rather a search query to display all the tables that contain a certain prefix. Something like what is displayed below (but is obviously incorrect)

SELECT TABLES LIKE chat_

So any table that has the chat prefix, would be displayed. I plan on formatting the output, so it's not going to be a raw output, and I also understand that "what idiot would display table names publicly", and security measures are being taken to prevent that "accidental" table drop (just trying to avoid a flame war). So, how is this accomplished?

A: 
SHOW TABLES LIKE 'chat_%';
Unknown
Thanks, I thought this is how you would do it.
Nik
+1  A: 

You can also use regular expressions, which allows a little more flexibility (though a performance cost):

SHOW TABLES WHERE tables_in_db REGEXP 'chat.*';

In this example, replace db with the database name of concern.

JYelton