zoukankan      html  css  js  c++  java
  • PostgreSql 获取所有的表、视图、字段、 主键

    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_type.typname as typename,pg_constraint.conname as pk_name from 
    pg_constraint  inner join pg_class 
    on pg_constraint.conrelid = pg_class.oid 
    inner join pg_attribute on pg_attribute.attrelid = pg_class.oid 
    and  pg_attribute.attnum = pg_constraint.conkey[1]
    inner join pg_type on pg_type.oid = pg_attribute.atttypid
    where pg_class.relname = 'tablename' 
    and pg_constraint.contype='p'
  • 相关阅读:
    HTML超文本标记语言(八)——表单<form>
    如何理解JavaScript中给变量赋值,是引用还是复制
    PostCSS 实战
    sass 工具库
    微信小程序-制作简易豆瓣笔记
    学习pano2vr制作html5全景笔记
    git命令笔记
    Gulp实战
    html5-离线存储
    html5
  • 原文地址:https://www.cnblogs.com/lucoo/p/5712585.html
Copyright © 2011-2022 走看看