How to Add Comments on Columns of MySQL Table

Reading Time: 4 minutes
11,422 Views

Sometimes if we are handle large projects in development, then at database level we need to add comments on columns to understand about the supported values. This gives the better vision to get the concept of use of column in tables.

What we mean by adding comments on columns to MySQL tables ?

As you can see, we have columns as role_id and status into a table. Role Id value contains an integer value and it is different for different user roles. So in value we have like 1, 2, 3 … and when we see at top of the column we have beautifully added a comment which is giving idea about those id values.

Learn more –

Inside this article we will see how to add comments on columns of MySQL Table. Let’s get started.


How to Add Comments on Columns MySQL Table

We have two options available to add comments on columns. Options are –

  • Manual adding comments.
  • Alter command of MySQL

By using these we can some extra informative information to columns for better vision over it’s role.

Manual Adding Comments

When we create a MySQL table via PhpMyAdmin interface, we should see this layout to define table scheme. In this list of structure option, we have a comments column. In this comments section we can pass to each row if we need.

Alter Command of MySQL

#Syntax:
ALTER TABLE table_name CHANGE column_name column_definition COMMENT "Your comment"

#Example:
ALTER TABLE `tbl_users` CHANGE `role_id` `role_id` varchar( 120 ) COMMENT '1 - Super Admin, 2 - Admin, 3 - Editor, 4 - Author' 
  
  • table_name -> Provide name of the table
  • column_name -> Pass column name where we need to add comment
  • column_definition -> Column definition means column name with data type

We hope this article helped you to learn about to add Comments on Columns of MySQL Table in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more