简体   繁体   English

mysql,如何查询表注释?

[英]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. 查询information_schema数据库中的COLUMNS表。

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. 另一种方法是执行SHOW CREATE TABLE mytable查询。 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. 此解决方案应该适合在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. 例如,如果您打算提取列注释以便在应用程序中使用,那么对information_schema.columns表的查询(如garnertb的答案中所提供的)将返回一个更易于以编程方式处理的结果集。 I would also specify a predicate on the table_schema column as well, because that table_name could appear in more than one database. 我还会在table_schema列上指定谓词,因为table_name可能出现在多个数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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