Add comment to column in MySQL using Python
MySQL server is an open-source relational database management system which is a major support for web-based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. In order to access MySQL databases from a web server we use various modules in Python such as PyMySQL, mysql.connector, etc.
A comment is a readable explanation or a statement placed in the SQL queries. It is used for the purpose of making the SQL statements easier for humans to understand. MySQL generally ignores them during the parsing of the SQL code. Comments can be written in a single line or multiple lines.
In this article, we’re using a database called test and which has a table called geeksfoegeeks. Look at the below image.
To check if there is any comment for any column, see below statement.
SHOW FULL COLUMNS FROM table_name;
Below is the image which shows that no column is associated with any kind of comment.
The statement to add any comment to a column is given below:
ALTER TABLE table_name MODIFY column_name type_of_that_column COMMENT ‘enter comment here’;
Below are some examples which depict how to add a comment to a column in a MySQL table using Python:
Adding Single line comment.
We could see that the comment “ENTER NAMES HERE” for column “Name” has been added.
Adding multi-line comments.
We could see that comments have been added successfully. Below is a screenshot of the MySQL database is also added.