Wednesday 4 February 2015

syntax for show tables not like in mysql

Mysql  supports "LIKE" in "SHOW TABLES" but not "NOT LIKE".

Example :


for LIKE operator

mysql> show tables like 'emp%';

+-----------------------------------------+
| Tables_in_Demo (tem%)                |
+-----------------------------------------+
| employee                                      |
+-----------------------------------------+

for NOT LIKE operator

mysql> show tables not like 'emp%';

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not like 'emp%'' at line 1

To handle this the correct syntax is :


You could use the WHERE clause extension, as in:
SHOW TABLES WHERE `Tables_in_<DatabaseName>` NOT LIKE 'tree%';
This is supported on MySQL ≥5.0.

Reference:

No comments:

Post a Comment