Table of Contents
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 –
- 10 Basic Commands of MySQL for Beginners
- Basics Overview of MySQL Stored Procedures
- Create and Call MySQL Stored Procedure
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.