Search code examples
phpmysqlcommentsinformation-schema

Information Schema Table Description / Comment


What is the query code to extract the Table Comment/Description? To get column descriptions is easy. Is there a URL or list of the various queries and options you can perform on Information schema and their applicable column-names options?

To clarify:

$sql = "SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.COLUMN_NAME WHERE `TABLE_SCHEMA` = '$dbnm' AND TABLE_NAME = '$tbl_nm' LIMIT 1";

This turns out nothing (obviously); I need to pull out an exact description of the table in question, individually not show all the information on a particular table.

I also need it in a form I can run an SQL query on it to make it usable....


Solution

  • ... FROM INFORMATION_SCHEMA.COLUMN_NAME ...
    

    There is no such table called COLUMN_NAME in the information_schema.

    If you want to get table comments, use this query:

    $sql = "SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES 
        WHERE TABLE_SCHEMA = '$dbnm' AND TABLE_NAME = '$tbl_nm'";
    

    If you want reference documentation for the tables in the information schema and their columns try: http://dev.mysql.com/doc/refman/5.6/en/information-schema.html

    Or else view it yourself:

    mysql> SHOW TABLES FROM INFORMATION_SCHEMA;
    mysql> DESC INFORMATION_SCHEMA.TABLES;