Navicat导出表结构到Excel或Word

Navicat导出表结构到Excel或Word

sql语句

language-sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SELECT
cols.COLUMN_NAME AS 字段,
cols.COLUMN_TYPE AS 数据类型,
IF(pks.CONSTRAINT_TYPE = 'PRIMARY KEY', 'YES', 'NO') AS 是否为主键,
IF(idxs.INDEX_NAME IS NOT NULL, 'YES', 'NO') AS 是否为索引,
cols.IS_NULLABLE AS 是否为空,
cols.COLUMN_DEFAULT AS 默认值,
cols.COLUMN_COMMENT AS 备注
FROM
INFORMATION_SCHEMA.COLUMNS AS cols
LEFT JOIN
INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS kc ON kc.TABLE_SCHEMA = cols.TABLE_SCHEMA AND kc.TABLE_NAME = cols.TABLE_NAME AND kc.COLUMN_NAME = cols.COLUMN_NAME
LEFT JOIN
INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS pks ON pks.TABLE_SCHEMA = kc.TABLE_SCHEMA AND pks.TABLE_NAME = kc.TABLE_NAME AND pks.CONSTRAINT_TYPE = 'PRIMARY KEY' AND kc.CONSTRAINT_NAME = pks.CONSTRAINT_NAME
LEFT JOIN
INFORMATION_SCHEMA.STATISTICS AS idxs ON idxs.TABLE_SCHEMA = cols.TABLE_SCHEMA AND idxs.TABLE_NAME = cols.TABLE_NAME AND idxs.COLUMN_NAME = cols.COLUMN_NAME
WHERE
cols.TABLE_SCHEMA = 'db' -- 替换为您的数据库名称
AND cols.TABLE_NAME = 'table' -- 替换为您的表名称
ORDER BY
cols.ORDINAL_POSITION ASC; -- 按列在表中的顺序排列

复制到excel

在查询结果中,Ctrl+A全选,然后复制。
到Excel中,自己写好表头,然后粘贴,就复制到Excel了。

复制到Word

从Excel全选数据,就可以直接复制到Word。

作者

Xiamu

发布于

2024-05-08

更新于

2024-08-11

许可协议

评论