Home >Database >Mysql Tutorial >Can I Add or Modify Comments on MySQL Columns?

Can I Add or Modify Comments on MySQL Columns?

Barbara Streisand
Barbara StreisandOriginal
2024-10-30 12:57:02552browse

Can I Add or Modify Comments on MySQL Columns?

Adding Comments to MySQL Columns

Question:

Can you add or modify comments on MySQL columns? The official documentation does not explicitly mention this feature.

Answer:

Yes, you can add or modify comments on MySQL columns using the ALTER TABLE statement.

For Column Comments:

To add or modify a comment on a specific column, use the following syntax:

ALTER TABLE <table_name> CHANGE <column_name> <column_name> <data_type> COMMENT '<comment>'

For example, to add a comment to the id column in the user table:

ALTER TABLE `user` CHANGE `id` `id` INT( 11 ) COMMENT 'id of user'

This will add the comment 'id of user' to the id column.

Note: The CHANGE clause is used to modify the column definition while preserving its existing data.

The above is the detailed content of Can I Add or Modify Comments on MySQL Columns?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn