Home > Database > Mysql Tutorial > body text

mysql adds comments to data tables and fields

王林
Release: 2020-01-26 21:29:50
forward
3891 people have browsed it

mysql adds comments to data tables and fields

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='表注释';
Copy after login

2 , Modify table comments

ALTER TABLE test_table COMMENT '修改表注释';
Copy after login

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'
Copy after login

4. Add column comments

alter table test_table add t_age int(11) comment '年龄'
Copy after login

5. Modify the column name with comments

ALTER TABLE test_table CHANGE t_age t_sex VARCHAR(4) COMMENT '性别'
Copy after login

6. Modify the column comments

ALTER TABLE test_table MODIFY COLUMN t_sex VARCHAR(30) NOT NULL COMMENT '男女'
Copy after login

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
Copy after login

8. Query table field information

SHOW FULL COLUMNS FROM test_table
Copy after login

9. Delete tables

-- 单删
  drop table 表  
-- 批删
  drop table 表1,表2,表3
Copy after login

10. Modify certain items in batches The field value

UPDATE test_table SET t_name = REPLACE(t_name, 'test', 't')
Copy after login

is as shown in the figure:

Example: Before running

mysql adds comments to data tables and fields

##After running:

mysql adds comments to data tables and fields

Recommended related article tutorials:

mysql tutorial

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template