当前位置:网站首页> 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;
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- [IELTS speaking] Anna's oral learning record part1
- Adavit -- dynamic network with adaptive selection of computing structure
- Demonstration of the development case of DAPP system for money deposit and interest bearing financial management
- DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
- 2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
- Cocoscreator+typescripts write an object pool by themselves
- 【编译原理】做了一半的LR(0)分析器
- Gd32f4xx serial port receive interrupt and idle interrupt configuration
- DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
- [compilation principle] LR (0) analyzer half done
猜你喜欢
Aardio - does not declare the method of directly passing float values
Matlab tips (27) grey prediction
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
欧洲生物信息研究所2021亮点报告发布:采用AlphaFold已预测出近1百万个蛋白质
Bipartite graph determination
Aardio - integrate variable values into a string of text through variable names
云原生技术--- 容器知识点
企業不想換掉用了十年的老系統
Machine test question 1
【编译原理】做了一半的LR(0)分析器
随机推荐
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
MATLAB小技巧(27)灰色预测
【全网首发】Redis系列3:高可用之主从架构的
three. JS gorgeous bubble effect
Dayu200 experience officer runs the intelligent drying system page based on arkui ETS on dayu200
Case recommendation: An Qing works with partners to ensure that the "smart court" is more efficient
Method of canceling automatic watermarking of uploaded pictures by CSDN
Aardio - construct a multi button component with customplus library +plus
Les entreprises ne veulent pas remplacer un système vieux de dix ans
项目复盘模板
DockerMySQL无法被宿主机访问的问题解决
View
Let's see through the network i/o model from beginning to end
Windows auzre background operation interface of Microsoft's cloud computing products
Mysql 身份认证绕过漏洞(CVE-2012-2122)
Extern keyword
Cocoscreator+typescripts write an object pool by themselves
C three ways to realize socket data reception
dockermysql修改root账号密码并赋予权限
Export MySQL table data in pure mode