简体   繁体   中英

Listing tables in mysql database

How do you list the names / fields of all the tables in a mysql database ?

Any code examples would be helpful,

Thanks!

You can use thsi query for all columns in your database and their corresponding table name-

SELECT TABLE_NAME, COLUMN_NAME 
FROM INFORMATION_SCHEMA.COLUMNS 

This will give list of all tables -

SHOW TABLES

For column names available in specific table, you can use any of below -

DESCRIBE table_name 
SHOW FIELDS FROM table_name 
SHOW COLUMNS FROM table_name 

To get list of all tables in a database the syntax is -

SHOW [FULL] TABLES [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr]

The LIKE clause, if present, indicates which table names to match. The WHERE clause can be given to select rows using more general conditions.

Reference - http://dev.mysql.com/doc/refman/5.1/en/show-tables.html

If you are using PHP as a server side language then it can be done as follows -

http://www.java2s.com/Code/Php/MySQL-Database/Getalltablesinadatabase.htm

In case you check export or import results, you can get metadata about your schema (including tables, triggers, and procedures/functions) using INFORMATION_SCHEMA to verify the new schema contains all required objects.

SELECT * FROM INFORMATION_SCHEMA.TABLES;
SELECT * FROM  INFORMATION_SCHEMA.TRIGGERS;
SHOW PROCEDURE STATUS;
SHOW FUNCTION status;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM