当前位置:网站首页>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 .
边栏推荐
- NFTScan 开发者平台推出 Pro API 商业化服务
- Pytest unit test series [v1.0.0] [pytest execute unittest test case]
- 监控界的最强王者,没有之一!
- MySQL中正则表达式(REGEXP)使用详解
- Nftscan Developer Platform launches Pro API commercial services
- B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
- Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
- Automatically update selenium driver chromedriver
- How to choose indoor LED display? These five considerations must be taken into account
- AcWing 4300. Two operations (minimum number of BFS searches)
猜你喜欢
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
docker启动mysql及-eMYSQL_ROOT_PASSWORD=my-secret-pw问题解决
借助这个宝藏神器,我成为全栈了
How to choose indoor LED display? These five considerations must be taken into account
asp读取oracle数据库问题
ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
每人每年最高500万经费!选人不选项目,专注基础科研,科学家主导腾讯出资的「新基石」启动申报...
同构+跨端,懂得小程序+kbone+finclip就够了!
机器人材料整理中的套-假-大-空话
Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi
随机推荐
js對JSON數組的增删改查
存币生息理财dapp系统开发案例演示
Method of canceling automatic watermarking of uploaded pictures by CSDN
[compilation principle] LR (0) analyzer half done
View
Huawei cloud gaussdb (for redis) unveils issue 21: using Gauss redis to achieve secondary indexing
docker mysql5.7如何设置不区分大小写
Financial professionals must read book series 6: equity investment (based on the outline and framework of the CFA exam)
Cloud native (32) | kubernetes introduction to platform storage system
Why are some people still poor and living at the bottom of society even though they have been working hard?
Project duplicate template
Dockermysql modifies the root account password and grants permissions
Demonstration of the development case of DAPP system for money deposit and interest bearing financial management
flinksql select id ,count(*) from a group by id .
问下各位,有没有flink sql生成作业的文档啊或是案列啊知道flink cli可以建表和指定目
浅谈现在的弊端与未来的发展
Should the jar package of MySQL CDC be placed in different places in the Flink running mode?
How to choose indoor LED display? These five considerations must be taken into account
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?