Home > Database > Mysql Tutorial > body text

How to query whether a data table exists in mysql

青灯夜游
Release: 2021-12-02 14:59:15
Original
24936 people have browsed it

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 = '需要查找的数据库名';
Copy after login

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

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

2. Determine whether the data table exists

The query SQL is as follows:

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

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

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

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template