If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > updating COMMENT metadata for tables and columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-30-07, 02:33
jezemine jezemine is offline
another indirection layer
 
Join Date: May 2004
Location: Seattle
Posts: 1,312
updating COMMENT metadata for tables and columns

I am looking for a way to edit the COMMENT metadata for a table or column after the table or column is already in existence. Anyone happen to know what the DDL for doing that would be? something like this perhaps (obviously these don't work, this is just to demonstrate what I would need):

ALTER TABLE ADD COMMENT 'this table is for blah'
ALTER TABLE MODIFY COLUMN ADD COMMENT 'this column is for blah'

this page says it's possible but then doesn't give an example, and it's not clear to me from the syntax of ALTER TABLE that it's even possible: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

Quote:
Originally Posted by dev.mysql.com
ALTER TABLE enables you to change the structure of an existing
table. For example, you can add or delete columns, create or destroy
indexes, change the type of existing columns, or rename columns or
the table itself. You can also change the comment for the table and
type of the table.
__________________
elsasoft.org
Reply With Quote
  #2 (permalink)  
Old 05-30-07, 05:02
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
ALTER TABLE <table> COMMENT = 'blah blah blah';
ALTER TABLE <table> MODIFY COLUMN <column> <col params> COMMENT = 'blah blah blah';
e.g.

ALTER TABLE `sales` MODIFY COLUMN ID INT NOT NULL COMMENT = 'blah blah blah';
Reply With Quote
  #3 (permalink)  
Old 05-30-07, 10:09
jezemine jezemine is offline
another indirection layer
 
Join Date: May 2004
Location: Seattle
Posts: 1,312
Thanks!

that's lame that you have to provide the entire column definition just to change the comment though - seems error prone.
__________________
elsasoft.org
Reply With Quote
  #4 (permalink)  
Old 05-30-07, 11:44
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
I agree, however it's the only way I believe that it's possible.
How does MySQL know if the alter table statement you are doing is supposed to change the column definition or not?
ALTER TABLE <table> MODIFY COLUMN ID COMMENT='blah blah' is non-conformative, how would it differentiate between this
ALTER TABLE <table> MODIFY COLUMN ID NOT NULL
without a special case switch?
Do you actually want to change it to NOT NULL? Or was it supposed to be VARCHAR NOT NULL ? It doesn't know. Hence the requirement for full syntax. It's anal but enforces restriction...
Reply With Quote
  #5 (permalink)  
Old 05-30-07, 11:55
jezemine jezemine is offline
another indirection layer
 
Join Date: May 2004
Location: Seattle
Posts: 1,312
Quote:
Originally Posted by aschk
ALTER TABLE <table> MODIFY COLUMN ID COMMENT='blah blah' is non-conformative
what do you mean? are you referring to ANSI compliance?

Quote:
Originally Posted by aschk
how would it differentiate between this
ALTER TABLE <table> MODIFY COLUMN ID NOT NULL without a special case switch?
Do you actually want to change it to NOT NULL? Or was it supposed to be VARCHAR NOT NULL ? It doesn't know. Hence the requirement for full syntax. It's anal but enforces restriction...
seems to me in the context of a full blown SQL parser it would be a simple matter to distinguish COMMENT from other keywords. but the point is moot since it obviously doesn't work the way I would have designed it.

thanks again for the syntax.
__________________
elsasoft.org
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On