Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql comments for the columns of a view?

Tags:

mysql

Is it possible in MySql to store comments for the columns of a view?

I know how to add comments to normal tables and columns but I am not sure if it is possible to do so for views. All I know is that views (for some aspects) behave just like a table and for this reason it is possible to run a query as such:

SELECT 
  column_name, column_comment 
FROM 
  information_schema.columns 
WHERE 
  table_name='myview';

But I don't know how to add the comment in the first place and haven't found a solution yet!

The reason I am doing this is that I am storing metadata for my application in the comment field and I would like tables and views to be identical.

like image 489
Michael Tremante Avatar asked Jan 14 '12 20:01

Michael Tremante


3 Answers

According to the create view syntax there is no way currently to add comments to the "columns" of a view even if the columns of a view are present in the information_schema.columns table:

http://dev.mysql.com/doc/refman/5.0/en/create-view.html

like image 96
Michael Tremante Avatar answered Nov 10 '22 11:11

Michael Tremante


I don't think you can add comments to the view "columns", but you can use the view to retrieve comments from the underlying table, use SHOW COLUMNS as you would when querying a table.

like image 2
AnthonyBlake Avatar answered Nov 10 '22 12:11

AnthonyBlake


Mysql has no metadata for view columns:

http://dev.mysql.com/doc/refman/5.0/en/views-table.html

So answer is NO.

like image 2
rkosegi Avatar answered Nov 10 '22 11:11

rkosegi