Mysql、高斯(Gauss)数据库获取表布局
MySQL:
获取表布局及(column_comment)注释
- SELECT *
- FROM information_schema.columns
- WHERE table_schema = 'your_schema'
- AND table_name = 'your_table';
复制代码 高斯(Gauss):
获取表布局
- SELECT *
- FROM information_schema.columns
- WHERE table_schema = 'your_schema'
- AND table_name = 'your_table';
复制代码 获取字段注释
- select
- a.attname as column_name,
- a.attnotnull,
- d.description as column_comment
- from pg_description d
- join pg_attribute a on
- d.objoid = a.attrelid
- and d.objsubid = a.attnum
- join pg_class c on
- a.attrelid = c.oid
- where
- c.relname = 'your_table'
复制代码 结合一下:
- -- aa.column_name 字段名-- t1.column_comment 注释-- aa.column_default 默认值-- aa.is_nullable 是否为空-- aa.data_type 数据类型-- aa.character_maximum_length 字符串类型大小 -- aa.numeric_precision, 数字类型大小-- aa.datetime_precision 时间类型大小SELECT aa.column_name,t1.column_comment,aa.column_default,aa.is_nullable,aa.data_type,aa.character_maximum_length, aa.numeric_precision, aa.datetime_precisionFROM INFORMATION_SCHEMA.COLUMNS as aaleft join ( select
- a.attname as column_name,
- a.attnotnull,
- d.description as column_comment
- from pg_description d
- join pg_attribute a on
- d.objoid = a.attrelid
- and d.objsubid = a.attnum
- join pg_class c on
- a.attrelid = c.oid
- where
- c.relname = 'your_table'
- )t1 on t1.column_name = aa.column_nameWHERE TABLE_NAME = 'your_table'
复制代码 拓展:
将得到得数据复制到Excel中,举行处理,即可得到想要的表布局数据
其中必要的处理:
- C:=IF(B1:B40="NO","否","")
- F:=IF(D1:D40="character varying","varying",IF(D1:D40="timestamp without time zone","timestamp",IF(D1:D40="numeric","numeric","")))
- G:=F1:F40&"("&E1:E40&")"
- 不足:部分大小数值需要手写,也可以在sql中处理
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |