FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


MySQL => Select tables by prefix





jcreus
Does anybody know a way of selecting all the databases which do NOT start with a given prefix? I have seen the way SHOW TABLES LIKE ... but it doesn't seem to accept NOT between tables and like. I have also seen some workarounds using information_schema but it doesn't seem to work. Any solutions available?

Help would be greatly appreciated. Thanks a lot.
jmraker
If you can't find any other solution, In mysql all the database names, and table names should be stored in a database that you could use mysql to read all the names of the databases and tables directly

You connect to the "information_schema" database and use

SELECT * FROM `TABLES` WHERE TABLE_NAME NOT LIKE "prefix%" AND TABLE_SCHEMA="your database name"

You might not be able to connect to the "information_schema" database though.
jcreus
jmraker wrote:
If you can't find any other solution, In mysql all the database names, and table names should be stored in a database that you could use mysql to read all the names of the databases and tables directly

You connect to the "information_schema" database and use

SELECT * FROM `TABLES` WHERE TABLE_NAME NOT LIKE "prefix%" AND TABLE_SCHEMA="your database name"

You might not be able to connect to the "information_schema" database though.


Thanks a lot! It seemed to bé the % letter? It works fine. Thanks a lot. (Anyway I had used a different but more complex approach, switching to this one for the simplicity).
Related topics
script backup database
MySQL problem (as usual)
Searching MySQL Database
Just uploaded. Shouldn't be jibberish.
SQL table troubles.
SQL script: String function how to?
Formatting mySQL date
Connecting to 2 different Mysql database and tables?
SQL.....Where to start?
UTF-8 from MySQL to PHP
"Drop Down List Box" Using PHP and MySql
Using select menu and sub select menu
MYSQL: How check what is the related tables
Help with a query[solved]
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.