How to get the table name and attributes of a Mysql database?

Asked

Viewed 74,978 times

33

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

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

5 answers

44


To view tables in a database:

SHOW TABLES;

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

DESC nome_da_tabela;
  • 6

    If you need to specify a Database: SHOW TABLES FROM banco

  • You can choose the seat using the command USE nomeDoBanco;, before the SHOW TABLES;

  • 1

    SHOW TABLES answers only a part of the question. Table attributes are in INFORMATION_SCHEMA

  • Yes, you can use information_schema to view more complete table information, but if you only need basic information like name, headline, etc. you can use "DESC" (as mentioned in that same answer) which is simpler.

17

You can use the query:

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

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

7

Taking the column data from a given table:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '<tabela>';

7

The correct is to make a query in the INFORMATION_SCHEMA database. You will get data like table type, record size avg, names and Storage Engine.

DESC INFORMATION_SCHEMA.TABLES;

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

2

select * from all_tables where tables like '%tabela desejada%'
  • 2

    This is Oracle! Not Mysql!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.