Mysql specific steps to create a table with explanations and add comments to tables and fields:
1. Create a table with explanations
CREATE TABLE test_table( t_id INT(11) PRIMARY KEY AUTO_INCREMENT COMMENT '设置主键自增', t_name VARCHAR(64) COMMENT '列注释' ) COMMENT='表注释';
2 , Modify table comments
ALTER TABLE test_table COMMENT '修改表注释';
3. View table comments (free learning video tutorial sharing: mysql video tutorial)
SELECT TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'test_table'
4. Add column comments
alter table test_table add t_age int(11) comment '年龄'
5. Modify the column name with comments
ALTER TABLE test_table CHANGE t_age t_sex VARCHAR(4) COMMENT '性别'
6. Modify the column comments
ALTER TABLE test_table MODIFY COLUMN t_sex VARCHAR(30) NOT NULL COMMENT '男女'
Note: When modifying, you must write the complete definition of the field, such as field type, Properties etc. Never overwrite other attributes defined in this field just to modify a comment.
7. Delete columns
alter table test_table drop column t_sex
8. Query table field information
SHOW FULL COLUMNS FROM test_table
9. Delete tables
-- 单删 drop table 表 -- 批删 drop table 表1,表2,表3
10. Modify certain items in batches The field value
UPDATE test_table SET t_name = REPLACE(t_name, 'test', 't')
is as shown in the figure:
Example: Before running
##After running: Recommended related article tutorials:The above is the detailed content of mysql adds comments to data tables and fields. For more information, please follow other related articles on the PHP Chinese website!