0

Please suggest how to add comments to all columns of an existing table in database?

for eg: i have a table Employee with columns emp_id, emp_name, emp_salary, emp_address.

Now, i want to add comments to each column of the table.

Please suggest how to achieve it in one command.

Saw a duplicate thread: Alter MySQL table to add comments on columns

But the suggested reply could not be understood!

Community
  • 1
  • 1
RosAng
  • 1,010
  • 2
  • 18
  • 42
  • Perhaps you need to explain why you don't understand the answer, as it does indeed seem to answer your question... – e.dan Jun 23 '14 at 08:46
  • possible duplicate of [Alter MYSQL Table To Add Comments on Columns](http://stackoverflow.com/questions/2162420/alter-mysql-table-to-add-comments-on-columns) – e.dan Jun 23 '14 at 08:47
  • Can you give your table schema so we can help perfectly – Sadikhasan Jun 23 '14 at 08:54
  • could not understand this: ALTER TABLE `user` CHANGE `id` `id` INT( 11 ) COMMENT 'id of user' Please let me know what 'id' 'id' means – RosAng Jun 23 '14 at 08:58
  • the first `id` indicates the field that is altered, the second `id` stands for the new name. In this example the name remains the same, thus the `id` `id`. – Michael Kunst Jun 23 '14 at 09:27

1 Answers1

3

Query:

ALTER TABLE Employee 
  MODIFY fieldname new_fieldname INT(11) COMMENT 'the comment you want to add',
  MODIFY fieldname2 new_fieldname2 INT(11) COMMENT 'comment for the seconds row',
  MODIFY fieldname3 new_fieldname3 INT(11) COMMENT 'comment for third row';

Note that you have to include the column definition again when adding the comment.

Michael Kunst
  • 2,978
  • 25
  • 40
  • hi thanks, but how do i add comments to all column at once? I mean to say, i have columns emp_id, emp_name, emp_salary, emp_address i want to add comments for all columns with a single command. – RosAng Jun 23 '14 at 10:12
  • see edits. modify statements must be comma separated, and then add a `;` after the last one – Michael Kunst Jun 23 '14 at 10:47
  • it did not work, in pl/sql i get error: ora-01735 invalid ALTER TABLE option. – RosAng Jun 25 '14 at 11:41