简体   繁体   中英

mysql, how to query the table comments?

i haven't found anything on this situation, and here is my question.

after i create a field in a database i can also leave a comment for that specific field, maybe a description of what that field means, etc.

I would like to query after it.

any ideas if this is possible? is there anything similar i could use?

Query the COLUMNS table in the information_schema database.

SELECT a.COLUMN_NAME, a.COLUMN_COMMENT
FROM  information_schema.COLUMNS a 
WHERE a.TABLE_NAME = 'YOUR_TABLE_NAME'

You can do similar queries for any type of element in your db (ie tables, triggers, etc).

我喜欢这样做 - 好又简单:

SHOW FULL COLUMNS FROM tablename;

Another alternative is to execute a SHOW CREATE TABLE mytable query. The column comments are included in the output, along with all sorts of other useful information about datatypes, maximum lengths, indexes, foreign keys, etc.

This solution should be suitable for someone working with the database in SQL.

If you are intending to pull the column comments for use in an application for example, then a query of the information_schema.columns table (as provided in the answer from garnertb) would return a result set that is easier to deal with programatically. I would also specify a predicate on the table_schema column as well, because that table_name could appear in more than one database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM