当前位置:网站首页>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 .
边栏推荐
- Dayu200 experience officer runs the intelligent drying system page based on arkui ETS on dayu200
- ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
- Two week selection of tdengine community issues | phase II
- NFTScan 开发者平台推出 Pro API 商业化服务
- 实现多彩线条摆出心形
- Enterprises do not want to replace the old system that has been used for ten years
- AcWing 4300. Two operations (minimum number of BFS searches)
- Ajout, suppression et modification d'un tableau json par JS
- 同一个作业有两个source,同一链接不同数据库账号,为何第二个链接查出来的数据库列表是第一个账号的
- How to choose indoor LED display? These five considerations must be taken into account
猜你喜欢
docker启动mysql及-eMYSQL_ROOT_PASSWORD=my-secret-pw问题解决
AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务...
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
Mysql 身份认证绕过漏洞(CVE-2012-2122)
Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi
Thinkphp5 multi table associative query method join queries two database tables, and the query results are spliced and returned
机器人材料整理中的套-假-大-空话
浅谈网络安全之文件上传
docker中mysql开启日志的实现步骤
The problem that dockermysql cannot be accessed by the host machine is solved
随机推荐
企业不想换掉用了十年的老系统
浅谈网络安全之文件上传
European Bioinformatics Institute 2021 highlights report released: nearly 1million proteins have been predicted by alphafold
儿童睡衣(澳大利亚)AS/NZS 1249:2014办理流程
每人每年最高500万经费!选人不选项目,专注基础科研,科学家主导腾讯出资的「新基石」启动申报...
面试题:AOF重写机制,redis面试必问!!!
DevSecOps软件研发安全实践——发布篇
Modules that can be used by both the electron main process and the rendering process
服务器的系统怎么选者
koa2对Json数组增删改查
[step on pit collection] attempting to deserialize object on CUDA device+buff/cache occupy too much +pad_ sequence
Method of canceling automatic watermarking of uploaded pictures by CSDN
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
Ajout, suppression et modification d'un tableau json par JS
How can Oracle CDC deserialize with jsondebeziumdeserializationschema
PDF批量拆分、合并、书签提取、书签写入小工具
Isomorphism + cross end, knowing applet +kbone+finclip is enough!
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