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;
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';
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';
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!