Home > Database > Mysql Tutorial > How Can I Retrieve MySQL Table Names Using a SELECT Statement?

How Can I Retrieve MySQL Table Names Using a SELECT Statement?

Barbara Streisand
Release: 2024-12-11 06:52:10
Original
214 people have browsed it

How Can I Retrieve MySQL Table Names Using a SELECT Statement?

Obtain Table Names with the SELECT Statement in MySQL

MySQL's SHOW TABLES command provides a convenient method to list all tables within a database. However, to insert these table names into another table directly, an alternative approach is required.

The question arises: is there a standard SELECT statement that can retrieve table names? The answer lies in the information_schema.tables system table.

To retrieve the table names of all databases, execute the following query:

SELECT table_name FROM information_schema.tables;
Copy after login

To narrow down the search to a specific database named 'my_database', use:

SELECT table_name FROM information_schema.tables
WHERE table_schema = 'my_database';
Copy after login

To insert the retrieved table names into another table, execute:

INSERT INTO table_name
    SELECT table_name FROM information_schema.tables
        WHERE table_schema = 'my_database';
Copy after login

For comprehensive documentation, refer to: http://dev.mysql.com/doc/refman/5.0/en/information-schema.html

The above is the detailed content of How Can I Retrieve MySQL Table Names Using a SELECT Statement?. 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