Blog for IT technical details

April 6, 2009

Get all the Tables in mySQL database

Filed under: Database — Tags: , , — admin @ 2:24 pm

INFORMATION_SCHEMA provides access to database metadata,  (data dictionary  or database catalog) such as the name of a database or table, the data type of a column, or access privileges. It is the information database, the place that stores information about all the other databases that the MySQL server maintains.

Here is an example of a statement that retrieves information from INFORMATION_SCHEMA.

mysql>

SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = ‘yourdatabasename ORDER BY table_name DESC;

You can use stored procedure to do the same thing.

mysql>

DROP PROCEDURE GetAlltables;
DELIMITER /
CREATE PROCEDURE GetAlltables()
BEGIN
SELECT table_name FROM information_schema.tables WHERE table_schema = ‘yourdatabasename’ ORDER BY table_name DESC;
END /
DELIMITER ;

Then call

CALL GetAlltables();

Powered by WordPress