Home > Database > Mysql Tutorial > How to Retrieve a List of Views in a MySQL Database?

How to Retrieve a List of Views in a MySQL Database?

Barbara Streisand
Release: 2024-10-31 10:12:45
Original
538 people have browsed it

How to Retrieve a List of Views in a MySQL Database?

The Conundrum of Retrieving MySQL View Listings

Upon encountering the challenge of compiling a list of views within a MySQL database, one may resort to the widely suggested query:

SELECT table_name
FROM information_schema.views
WHERE information_schema.views.table_schema LIKE 'view%';
Copy after login

However, this approach often yields an unexpected result: an empty set. Frustrated by this elusive information, further attempts to access views using the views or tables tables within the information_schema database prove futile, resulting in the enigmatic error: "Incorrect database name."

The Illumination of the Solution

To illuminate the path to success, let us consider an alternate approach:

SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW';
Copy after login

This query directly queries the target database, bypassing the information_schema database altogether. By specifying the TABLE_TYPE parameter as 'VIEW', we effectively filter the results to include only tables that possess the view attribute.

This refined query grants access to a comprehensive list of all views residing within the targeted database, providing the clarity sought after.

The above is the detailed content of How to Retrieve a List of Views in a MySQL Database?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template