mysql database to add a comment field information

Copyright: https://blog.csdn.net/xichengqc/article/details/90019798

When you create a table using mysql database, it is recommended to add annotations, some company policy is the need to add a comment. If you forget to add when you create a table, there may be some modifications late pit, this article is used to record their course to avoid the pit:

  1. First, the field attribute is not changed after modifications, or may be a direct result of the next abnormal operation table data if the library is online, that accident .
    Therefore, we must first determine the properties of the fields in the table
SHOW CREATE TABLE jrm_hot_words

The results are as follows (information shown is the latest attribute table & field):

CREATE TABLE `jrm_hot_words` ( `id` int(11) NOT NULL AUTO_INCREMENT, `words` varchar(128) DEFAULT NULL COMMENT '搜索词', `defaultShow` tinyint(4) DEFAULT NULL COMMENT '是否默认显示', `sort` int(11) DEFAULT NULL COMMENT '显示顺序', `created_time` datetime NOT NULL, `modified_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=utf8
  1. Analysis table information:
    1. Field behind the field properties are shared, for example: NOT NULL, AUTO_INCREMENT, DEFAULT NULL, etc.
    2. Attribute is a table attribute outside parentheses, must not be modified , for example: ENGINE, CHARSET etc.
    3. Special attention: PRIMARY KEY also belong to the table attributes without modification
  2. Write SQL, you can change multiple fields together
ALTER TABLE jrm_hot_words MODIFY COLUMN id int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键ID', 
MODIFY COLUMN created_time datetime NOT NULL COMMENT '创建时间',
MODIFY COLUMN modified_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

Guess you like

Origin blog.csdn.net/xichengqc/article/details/90019798