Home  >  Article  >  Database  >  How to query whether a data table exists in mysql

How to query whether a data table exists in mysql

青灯夜游
青灯夜游Original
2021-12-02 14:59:1524820browse

In mysql, you can use the "select from" statement to query whether the specified data table exists, the syntax is "select*from information_schema.TABLES where TABLE_NAME = 'The name of the data table to be queried';".

How to query whether a data table exists in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

How to use SQL query statements to determine whether the database and data tables exist?

1. Determine whether the database exists

The query SQL is as follows:

select * from information_schema.SCHEMATA 
where SCHEMA_NAME = '需要查找的数据库名';

You can also fuzzy query, the SQL is as follows:

select * from information_schema.SCHEMATA 
where SCHEMA_NAME like '%需要查询的数据库名的部分名称%';

2. Determine whether the data table exists

The query SQL is as follows:

select * from information_schema.TABLES 
where TABLE_NAME = '需要查询的数据表名';

You can also fuzzy query, the SQL is as follows:

select * from information_schema.TABLES 
where TABLE_NAME like '%需要查询的数据表名的部分名称%';

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to query whether a data table exists in mysql. 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