当前位置:网站首页> mysql查看表结构的三种方法总结
mysql查看表结构的三种方法总结
2022-07-06 15:36:00 【1024问】
mysql查看表结构
1. show create table
2. desc
3. information_schema.COLUMNS
获取所有的表结构及备注
根据库名导出所有表信息
根据库名导出所有表名及表备注
mysql获取整个库的所有表,及表结构
mysql查看表结构1. show create tableshow create table 表名称
这个语句每次本能想出的,语义好记,可以直接查看建表语句,但不便于代码处理。
2. descdesc 表名称
这个语句简单易用,可以获取到 COLUMNS 中的比较重要的字段:名称、类型、是否为空、键、默认值、额外信息。但无法获取字段的注释。
3. information_schema.COLUMNSselect * from information_schema.COLUMNS where TABLE_SCHEMA = '库名称' and TABLE_NAME = '表名称'
相对show create table而言,相对简单,信息全面,可以查询出来字段的名称、类型、键、权限、注释和其他信息。为了获取字段名称,故我脚本中使用这个作为获取表结构的方法。
附:information_schema.COLUMNS字段和含义
字段名称及含义
TABLE_CATALOG
表类型(没搞懂干啥用?)
TABLE_SCHEMA
所属库名称
TABLE_NAME
表名称
COLUMN_NAME
字段名称
ORDINAL_POSITION
位置序号
COLUMN_DEFAULT
默认值
IS_NULLABLE
是否可为空
DATA_TYPE
数据类型
CHARACTER_MAXIMUM_LENGTH
字符串最大长度(数值类型为空)
CHARACTER_OCTET_LENGTH
字符串最大存储长度(一般与上一字段相同)
NUMERIC_PRECISION
数值精度(非数值类型为空)
NUMERIC_SCALE
数值小数位数(非数值类型为空)
DATETIME_PRECISION
日期精度
CHARACTER_SET_NAME
编码方式
COLLATION_NAME
排序方式
COLUMN_TYPE
字段类型
COLUMN_KEY
字段涉及的key(主键、唯一键等)
EXTRA
其他(如 auto_increment)
PRIVILEGES
权限
COLUMN_COMMENT
字段注释
GENERATION_EXPRESSION
代表达式(没搞懂,mysql可以表继承?)
SELECT *FROM information_schema.`TABLES`WHERE TABLE_SCHEMA = 'db_name'
根据库名导出所有表名及表备注SELECT TABLE_NAME, TABLE_COMMENTFROM information_schema.`TABLES`WHERE TABLE_SCHEMA = 'db_name';
mysql获取整个库的所有表,及表结构SELECT TABLE_SCHEMA AS '库名', TABLE_NAME AS '表名', COLUMN_NAME AS '列名', ORDINAL_POSITION AS '列的排列顺序', COLUMN_DEFAULT AS '默认值', IS_NULLABLE AS '是否为空', DATA_TYPE AS '数据类型', CHARACTER_MAXIMUM_LENGTH AS '字符最大长度', NUMERIC_PRECISION AS '数值精度(最大位数)', NUMERIC_SCALE AS '小数精度', COLUMN_TYPE AS '列类型', COLUMN_KEY 'KEY', EXTRA AS '额外说明', COLUMN_COMMENT AS '注释'FROM information_schema.`COLUMNS`WHERE TABLE_SCHEMA = 'db_name'ORDER BY TABLE_NAME, ORDINAL_POSITION;
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- 监控界的最强王者,没有之一!
- C three ways to realize socket data reception
- The difference between enumeration and define macro
- Redis persistence mechanism
- MySQL ---- first acquaintance with MySQL
- Improving Multimodal Accuracy Through Modality Pre-training and Attention
- (18) LCD1602 experiment
- 如何实现文字动画效果
- Puppeter connects to the existing Chrome browser
- OpenNMS separation database
猜你喜欢
How to confirm the storage mode of the current system by program?
Cocoscreator+typescripts write an object pool by themselves
Export MySQL table data in pure mode
Aardio - construct a multi button component with customplus library +plus
【编译原理】做了一半的LR(0)分析器
Bipartite graph determination
儿童睡衣(澳大利亚)AS/NZS 1249:2014办理流程
On the problems of born charge and non analytical correction in phonon and heat transport calculations
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
Mysql 身份认证绕过漏洞(CVE-2012-2122)
随机推荐
CocosCreator+TypeScripts自己写一个对象池
Machine test question 1
2022-07-05 use TPCC to conduct sub query test on stonedb
European Bioinformatics Institute 2021 highlights report released: nearly 1million proteins have been predicted by alphafold
【全网首发】Redis系列3:高可用之主从架构的
室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内
What are the specific steps and schedule of IELTS speaking?
2014阿里巴巴web前实习生项目分析(1)
Redis 持久化机制
Demonstration of the development case of DAPP system for money deposit and interest bearing financial management
Bipartite graph determination
Redis persistence mechanism
企業不想換掉用了十年的老系統
关于声子和热输运计算中BORN电荷和non-analytic修正的问题
OpenSSL:适用TLS与SSL协议的全功能工具包,通用加密库
Windows Auzre 微软的云计算产品的后台操作界面
POJ 1258 Agri-Net
poj 1094 Sorting It All Out (拓扑排序)
CRMEB商城系统如何助力营销?
Typescript get function parameter type