问题
As you guys propably know, there's the possibility to add a comment to a column in MySQL. Now I was wondering how I could obtain this comment via PHP/MySQL. I was searching the web but I didn't find any solution yet. Do you guys have any idea/solution for this problem?
Greetings!
回答1:
SELECT
COLUMN_COMMENT
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA = 'db-name' AND
TABLE_NAME = 'table-name' AND
COLUMN_NAME = 'column-name'
http://dev.mysql.com/doc/refman/5.0/en/columns-table.html
回答2:
Just use this SQL:
SHOW FULL COLUMNS FROM myTable
http://dev.mysql.com/doc/refman/5.0/en/show-columns.html
The FULL keyword causes the output to include the column collation and comments, as well as the privileges you have for each column.
回答3:
Data regarding MySQL's tables in stored in the information_schema
views.
You should be able to get it from there. This requires root privileges.
SELECT table_schema, table_name, column_comment
FROM INFORMATION_SCHEMA.`columns` c
WHERE c.table_schema = 'mydatabase'
AND c.table_name = 'mytable'
AND c.column_name = 'myfield'
回答4:
You can fetch those metadata from the information_schema
database.
Ex:
SELECT column_name, column_comment FROM information_schema.columns WHERE table_name = 'user'
Where user is your table name.
回答5:
If you have correct privileges you could make this query:
$query = "SHOW FULL COLUMNS from node;";
$result = mysql_query($query);
And then fetch the results (there is a column named Comment
that holds the comments)
回答6:
Use the SQL command SHOW FULL COLUMNS
as described in the MySQL manual. Its output contains the comments.
来源:https://stackoverflow.com/questions/6752169/how-to-obtain-column-comments-from-sql