這是一個正確的方法。 (只是被表格名稱周圍的「[]」大括號所困惑 - 這些很可能不是實際名稱的一部分,所以需要刪除)
此外,它是一種有效的方法:由於您提供常數都table_schema
以及爲table_name
,你因此利用INFORMATION_SCHEMA optimizations,在該表中沒有連開:
explain select count(*) from information_schema.tables where table_schema='world' and table_name='City';
+----+-------------+--------+------+---------------+-------------------------+---------+------+------+---------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+---------------+-------------------------+---------+------+------+---------------------------------------------------+
| 1 | SIMPLE | tables | ALL | NULL | TABLE_SCHEMA,TABLE_NAME | NULL | NULL | NULL | Using where; Skip_open_table; Scanned 0 databases |
+----+-------------+--------+------+---------------+-------------------------+---------+------+------+---------------------------------------------------+
提供的「SHOW TABLES」的解決方案是好的,太 - 和幾乎一樣就像Java/Python /無論代碼如何。其結果是有效的ResultSet:
SHOW TABLES FROM world LIKE 'City';
+------------------------+
| Tables_in_world (City) |
+------------------------+
| City |
+------------------------+
但只完成了故事:它不是標準的SQL語法 - 如果你正在使用像某些種類的ORM一些框架,你可能並不總是能夠用這種類型的查詢來解決問題(因爲我記得EJB3不會讓你這樣做)。
此外,它很難解析服務器端,請參閱:Reading results of SHOW statements, on server side,雖然這可能不是你的問題。
謝謝你..它的工作.. – 2012-07-06 07:24:07
很高興它幫助你。 – 2012-07-06 07:26:46