PostgresSql 中查询库中所有的表以及表中字段、主键、唯一、外键,查询某一个表中的所有字段查询某一个表中的所有字段

PostgresSql 中查询库中所有的表以及表中字段、主键、唯一、外键,查询某一个表中的所有字段

查询库中所有表

select relname as TABLE_NAME ,col_description(c.oid, 0) as COMMENTS from pg_class c
where  relkind = 'r' and relname not like 'pg_%' and relname not like 'sql_%'  order by relname

查询某一个表中的所有字段

select
	table_name,
	column_name,
	data_type,
	udt_name,
	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_precision_radix,
	numeric_scale,
	datetime_precision,
	interval_type,
	interval_precision,
	character_set_catalog,
	character_set_schema,
	character_set_name,
	collation_catalog,
	collation_schema,
	collation_name,
	domain_catalog,
	domain_schema,
	domain_name,
	udt_catalog,
	udt_schema,
	udt_name,
	scope_catalog,
	scope_schema,
	scope_name,
	maximum_cardinality,
	dtd_identifier,
	is_self_referencing,
	is_identity,
	identity_generation,
	identity_start,
	identity_increment,
	identity_maximum,
	identity_minimum,
	identity_cycle,
	is_generated,
	generation_expression,
	is_updatable
from
	information_schema. columns
where
	table_schema = 'public'
and table_name = '表名称 ';

在这里插入图片描述

查询表中所有字段、主键、唯一、外键、是否为空

select 
'true' as list,
'true' as edit,
'false' as search,
a.attname as column_name,
format_type(a.atttypid,a.atttypmod) as data_type,
(case when atttypmod-4>0 then atttypmod-4 else 0 end)data_length,
(case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and contype='p')>0  then 'Y' else 'N' end) as P,
(case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and contype='u')>0  then 'Y' else 'N' end) as U,
(case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and contype='f')>0  then 'Y' else 'N' end) as R,
(case when a.attnotnull=true  then 'Y' else 'N' end) as nullable,
col_description(a.attrelid,a.attnum) as comment,
'XEditText' as control
from  pg_attribute a
where attstattarget=-1 
and attrelid = (select oid from pg_class where relname ='userinfo')

其他信息,PostgresSql 数据库获取所有表的索引信息

PostgresSql 数据库获取所有表的索引信息

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值