How do I get the name and attributes of tables from a MySQL database?

31

How to get the names of all tables in the MySQL database?

How to get the attributes (name, type, etc ...) of a given table in the MySQL database?

    
asked by rray 11.12.2013 в 18:08
source

5 answers

42

To view the tables in a database:

SHOW TABLES;

To view the table structure with name, type, etc.:

DESC nome_da_tabela;
    
answered by 11.12.2013 / 18:10
source
15

You can use the query:

SELECT * FROM information_schema.tables WHERE table_schema = 'nome-do-banco';

It shows the names of the tables and also information like the engine used, creation date, etc.

    
answered by 11.12.2013 в 18:15
6

Correct is to query the INFORMATION_SCHEMA database. You'll get data like the type of tables, avg the size of the records, plus the names and the Storage Engine.

DESC INFORMATION_SCHEMA.TABLES;

It will give you a good knowledge of what you can look for per table. Remembering that TODO SHOW command has correlation with tables in INFORMATION_SCHEMA

    
answered by 13.12.2013 в 02:18
6

Taking the data from the columns of a given table:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '<tabela>';
    
answered by 09.12.2015 в 09:03
2
select * from all_tables where tables like '%tabela desejada%'
    
answered by 12.12.2013 в 16:57