How to read comments from MySQL table fields?

0

This command

  

SHOW COLUMNS FROM [table name];

Show the fields of a table and the most important details of them

I need to read the field comments, eg:

  

COLUMN cod_id INT (10) UNSIGNED NOT NULL COMMENT 'CODE   CLIENT '

This part I got in the create code of the table

You should read " COMMENT " content

    
asked by anonymous 09.08.2018 / 15:42

2 answers

3

There is a database called information_schema , this database is responsible for storing the structures of all databases.

To get the comment from a column you can select the table COLUMNS :

SELECT a.'COLUMN_COMMENT'
FROM 'information_schema'.'COLUMNS' a
WHERE a.'TABLE_SCHEMA' = 'seu_banco' AND a.'TABLE_NAME' = 'sua_tabela' AND a.'COLUMN_NAME' = 'sua_coluna';

Incidentally, this table stores all the information in a column, not just the comment. This database is also useful for other things, such as getting all the information from the tables of a specific bank:

SELECT * FROM 'information_schema'.'TABLES' a
WHERE a.'TABLE_SCHEMA' = 'seu_banco'
    
09.08.2018 / 15:51
0

I already found the command

  

SHOW FULL COLUMNS FROM [TABLE];

The source: link

    
09.08.2018 / 15:51