How to read comments from Mysql table fields?

Asked

Viewed 823 times

0

This command

SHOW COLUMNS FROM [table name];

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

I need to read the field comments, example:

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

This part I picked up in the table create code

I would need to read with "COMMENT"

  • 1

    Look at that answer: Link

2 answers

3

There is a database called information_schema, that 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';

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

SELECT * FROM `information_schema`.`TABLES` a
WHERE a.`TABLE_SCHEMA` = 'seu_banco'
  • The source would be this: FOUNTAIN? If so, put it in the answer.

  • So Roberto at the same time that you were putting your answer I ended up finding a very simple command: SHOW FULL COLUMNS FROM TABLE; FULL brings all the details of the table, I thank you for the answer

  • @That’s not the source, I even built the SELECT manually on my menangement.

  • @Marcelo, the important thing is to have the problem solved.

0


Browser other questions tagged

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