How to comment / document a table?

Asked

Viewed 2,505 times

4

I saw in a Postgresql database that each table and each table field has a comment explaining what each one is for. Following model below:

inserir a descrição da imagem aqui

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

1 answer

7


Yes it is possible just add the clasp COMMENT in the definition of the column or table.

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 flap info the comments in the table and in the columns comments for each column.

inserir a descrição da imagem aqui

Based on: Show Comment of Fields FROM Mysql Table

  • has how to print?

  • @Italorodrigo already updated the answer.

Browser other questions tagged

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