I'm wondering if it's possible to change only comment on a column in mysql without change the column definition data like name, type and key.
Example:
ALTER TABLE `user` CHANGE `id` `id` INT(11) COMMENT 'id of user'
Can i change only the comment is this example ?
Thanks in adavance.
The comments can be added to the MySQL columns while creating a table by adding the COMMENT keyword after the column definition, as shown above for column emp_name. The table is created successfully with comments. Confirm the same in column information using MySQL workbench.
The syntax to modify a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name MODIFY column_name column_definition [ FIRST | AFTER column_name ]; table_name. The name of the table to modify.
To enforce NOT NULL for a column in MySQL, you use the ALTER TABLE .... MODIFY command and restate the column definition, adding the NOT NULL attribute.
To edit column comments select a column by checking the box to the left of its name and click on the Change button. This action will open a column editor where you can add or edit a comment in the Comments field.
How can we use MySQL ALTER TABLE command for adding comments on columns? We can use ‘COMMENT’ keyword with ALTER TABLE command while modifying the column to add comments on columns. For example if we want to add comment in column ‘id’ of table ‘testing’ then following query will do it −
The MySQL ALTER COLUMN query is a MySQL statement that is responsible to change the structure of a table, either for adding a table column, altering the column, renaming the column, removing the column or renaming the table itself.
The word COLUMN is optional and can be omitted. Multiple ADD, ALTER , DROP, and CHANGE clauses are permitted in a single ALTER TABLE statement, separated by commas. This is a MySQL extension to standard SQL, which permits only one of each clause per ALTER TABLE statement. For example, to drop multiple columns in a single statement, do this:
There are two options you can either add the table column after the last column existing in the table using AFTER ColumnNameKeyword or, as first column using FIRST ColumnNamekeyword. But if these options are not provided in the ALTER ADD COLUMN query then, the new table column will be affixed at the end of the list of columns in the table.
According to the MySQL specification, you must repeat the entire column definition if you want to redefine the comment:
ALTER TABLE user MODIFY id INT(11) COMMENT 'id of user';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With