当前位置:网站首页>Summary of three methods for MySQL to view table structure
Summary of three methods for MySQL to view table structure
2022-07-06 23:19:00 【1024 questions】
mysql View table structure
1. show create table
2. desc
3. information_schema.COLUMNS
Get all the table structures and comments
Export all table information according to the library name
Export all table names and table comments according to the library name
mysql Get all tables of the entire library , And table structure
mysql View table structure 1. show create tableshow create table The name of the table This sentence comes up instinctively every time , Semantic memorization , You can directly view the table creation statement , But it is not convenient for code processing .
2. descdesc The name of the table This statement is easy to use , Can be obtained COLUMNS The more important fields in : name 、 type 、 Is it empty 、 key 、 The default value is 、 Additional information . But cannot get the comment of the field .
3. information_schema.COLUMNSselect * from information_schema.COLUMNS where TABLE_SCHEMA = ' Library name ' and TABLE_NAME = ' The name of the table 'relative show create table for , Relatively simple , Comprehensive information , You can query the name of the field 、 type 、 key 、 jurisdiction 、 Notes and other information . To get the field name , So I use this as a method to get the table structure in my script .
attach :information_schema.COLUMNS Fields and meanings
Field name and meaning
TABLE_CATALOG Table type ( I didn't understand what to do ?)
TABLE_SCHEMA Library name
TABLE_NAME The name of the table
COLUMN_NAME Field name
ORDINAL_POSITION Location number
COLUMN_DEFAULT The default value is
IS_NULLABLE Can it be empty
DATA_TYPE data type
CHARACTER_MAXIMUM_LENGTH Maximum string length ( The value type is empty )
CHARACTER_OCTET_LENGTH Maximum storage length of string ( It is generally the same as the previous field )
NUMERIC_PRECISION Numerical accuracy ( Non numeric type is empty )
NUMERIC_SCALE Number of decimal places ( Non numeric type is empty )
DATETIME_PRECISION Date precision
CHARACTER_SET_NAME Encoding mode
COLLATION_NAME sort order
COLUMN_TYPE Field type
COLUMN_KEY Fields involved key( Primary key 、 Unique key, etc )
EXTRA other ( Such as auto_increment)
PRIVILEGES jurisdiction
COLUMN_COMMENT Annotation fields
GENERATION_EXPRESSION Represents the expression ( I don't understand ,mysql Table inheritance ?)
SELECT *FROM information_schema.`TABLES`WHERE TABLE_SCHEMA = 'db_name' Export all table names and table comments according to the library name SELECT TABLE_NAME, TABLE_COMMENTFROM information_schema.`TABLES`WHERE TABLE_SCHEMA = 'db_name';mysql Get all tables of the entire library , And table structure SELECT TABLE_SCHEMA AS ' Library name ', TABLE_NAME AS ' Table name ', COLUMN_NAME AS ' Name ', ORDINAL_POSITION AS ' Order of columns ', COLUMN_DEFAULT AS ' The default value is ', IS_NULLABLE AS ' Is it empty ', DATA_TYPE AS ' data type ', CHARACTER_MAXIMUM_LENGTH AS ' Maximum character length ', NUMERIC_PRECISION AS ' Numerical accuracy ( Maximum number )', NUMERIC_SCALE AS ' Decimal precision ', COLUMN_TYPE AS ' Column type ', COLUMN_KEY 'KEY', EXTRA AS ' Additional instructions ', COLUMN_COMMENT AS ' notes 'FROM information_schema.`COLUMNS`WHERE TABLE_SCHEMA = 'db_name'ORDER BY TABLE_NAME, ORDINAL_POSITION;The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .
边栏推荐
- 使用MitmProxy离线缓存360度全景网页
- How can Oracle CDC deserialize with jsondebeziumdeserializationschema
- js导入excel&导出excel
- js對JSON數組的增删改查
- Pytest unit test series [v1.0.0] [pytest execute unittest test case]
- NFTScan 开发者平台推出 Pro API 商业化服务
- ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
- Demonstration of the development case of DAPP system for money deposit and interest bearing financial management
- Use mitmproxy to cache 360 degree panoramic web pages offline
- Docker starts MySQL and -emysql_ ROOT_ Password = my secret PW problem solving
猜你喜欢

Koa2 addition, deletion, modification and query of JSON array

Motion capture for snake motion analysis and snake robot development

Cocoscreator+typescripts write an object pool by themselves

B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万

Efficient ETL Testing
Docker starts MySQL and -emysql_ ROOT_ Password = my secret PW problem solving

What can be done for traffic safety?

asp读取oracle数据库问题

今日睡眠质量记录78分

COSCon'22 社区召集令来啦!Open the World,邀请所有社区一起拥抱开源,打开新世界~
随机推荐
Nftscan Developer Platform launches Pro API commercial services
Case recommendation: An Qing works with partners to ensure that the "smart court" is more efficient
每日刷题记录 (十五)
华为云GaussDB(for Redis)揭秘第21期:使用高斯Redis实现二级索引
Cover fake big empty talk in robot material sorting
云原生(三十二) | Kubernetes篇之平台存储系统介绍
Efficient ETL Testing
让我们,从头到尾,通透网络I/O模型
同构+跨端,懂得小程序+kbone+finclip就够了!
让 Rust 库更优美的几个建议!你学会了吗?
On file uploading of network security
Enterprises do not want to replace the old system that has been used for ten years
Docker starts MySQL and -emysql_ ROOT_ Password = my secret PW problem solving
Hard core observation 545 50 years ago, Apollo 15 made a feather landing experiment on the moon
实现多彩线条摆出心形
Financial professionals must read book series 6: equity investment (based on the outline and framework of the CFA exam)
室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
Graphite document: four countermeasures to solve the problem of enterprise document information security
TDengine 社区问题双周精选 | 第二期