How to comment / document a table?

4

I saw in a PostGreSQL database that each table and each table field has a comment explaining what each one is for. Follow the template below:

I want to know if in MySQL it is possible to do something similar. If not, is there any external program to do this documentation?

    
asked by anonymous 20.02.2017 / 00:07

1 answer

7

Yes you can just add the COMMENT class in the column or table definition.

CREATE TABLE pessoa(
  id INT NOT NULL AUTO_INCREMENT COMMENT 'chave primária',
  nome VARCHAR(50) COMMENT 'coluna com o nome',
  email VARCHAR(50) COMMENT 'contato da pessoas',
  PRIMARY KEY(id)
)COMMENT 'tabela contendo informações de pessoas'

To retrieve comments from tables / columns you can use the command:

SHOW FULL COLUMNS FROM pessoa

For a more refined query use the information_schema :

SELECT table_name, table_comment FROM information_schema.tables
WHERE table_schema = 'nome_da_database'

If you use the workbench click on the icon with the letter i on the info tab the table comments are shown and in the columns the comments referring to each column.

Basedon: Show Comment of Fields FROM Mysql Table

    
20.02.2017 / 00:11