加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSql 获取所有的表、视图、字段、 主键

发布时间:2020-12-13 17:01:22 所属栏目:百科 来源:网络整理
导读:转载自http://www.cnblogs.com/lucoo/p/5712585.html PostgreSQL获取数据库中所有view名视图: SELECT viewname FROM pg_views WHERE schemaname = ' public ' postgreSQL获取数据库中所有table名 表: SELECT tablename FROM pg_tables WHERE tablename NOT

转载自http://www.cnblogs.com/lucoo/p/5712585.html


PostgreSQL获取数据库中所有view名视图:

SELECT   viewname   FROM   pg_views  
WHERE     schemaname ='public'  

postgreSQL获取数据库中所有table名 表:

SELECT tablename FROM pg_tables WHERE tablename NOT LIKE pg%' AND tablename NOT LIKE sql_%' ORDER BY tablename;

postgreSQL获取某个表tablename 所有字段名称 , 类型,备注,是否为空 等

SELECT col_description(a.attrelid,a.attnum) as comment,pg_type.typname as typename,a.attname as name,a.attnotnull as notnull FROM pg_class as c,pg_attribute as a inner join pg_type on pg_type.oid = a.atttypid where c.relname = tablename' and a.attrelid = c.oid and a.attnum>0

postgreSQL获取某个表tablename 的主键信息

select pg_attribute.attname as colname,pg_constraint.conname as pk_name from 
pg_constraint  join pg_class 
on pg_constraint.conrelid = pg_class.oid 
join pg_attribute on pg_attribute.attrelid = pg_class.oid 
and  pg_attribute.attnum = pg_constraint.conkey[1]
= pg_attribute.atttypid
where pg_class.relname ' 
and pg_constraint.contypep'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读