MySQL:
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_precision FROM INFORMATION_SCHEMA.COLUMNS as aa left 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_name WHERE 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中处理