Home  >  Article  >  Database  >  MySQL - Query whether the specified database and table exist

MySQL - Query whether the specified database and table exist

黄舟
黄舟Original
2017-03-14 14:50:391632browse

1. Check whether the specified database exists

SELECT information_schema.SCHEMATA.SCHEMA_NAME FROM information_schema.SCHEMATA where SCHEMA_NAME='databaseName';

2. Check whether a certain table exists under the specified database

<p style="margin-bottom: 7px;">SELECT DISTINCT t.table_name, n.SCHEMA_NAME FROM information_schema.TABLES t, information_schema.SCHEMATA n WHERE t.<br/><br/>table_name = &#39;tableName&#39; AND n.SCHEMA_NAME = &#39;databaseName&#39;;</p>

The above is the detailed content of MySQL - Query whether the specified database and table exist. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn