ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 查询主外键

查询主外键

原创 Linux操作系统 作者:gyhgood 时间:2013-01-14 16:10:05 0 删除 编辑

-- 查询父表关联外键

  select   c.constraint_name,cc.column_name,rcc.owner,rcc.table_name,rcc.column_name  

  from   user_constraints   c,user_cons_columns   cc,user_cons_columns   rcc  

  where   c.owner='DEV_MST'  

  and   c.table_name ='ITEM_MASTER'  

  and   c.constraint_type='R'  

  and   c.owner=cc.owner  

  and   c.constraint_name=cc.constraint_name  

  and   c.r_owner=rcc.owner  

  and   c.r_constraint_name=rcc.constraint_name  

  and   cc.position=rcc.position  

  order   by   c.constraint_name,cc.position;  

    

  --查询子表关联外键

  select   rcc.owner,rcc.table_name,rcc.constraint_name,rcc.column_name,c.table_name,c.constraint_name,cc.column_name      

  from   user_constraints   c,user_cons_columns   cc,user_cons_columns   rcc  

  where c.owner='DEV_MST'  

  and   rcc.table_name ='ITEM_MASTER'  

  and   c.constraint_type='R'  

  and   c.owner=cc.owner  

  and   c.constraint_name=cc.constraint_name  

  and   c.r_owner=rcc.owner  

  and   c.r_constraint_name=rcc.constraint_name  

  and   cc.position=rcc.position  

  order   by   c.constraint_name,cc.position  

    

      

  -- PK和唯一索引

  select   c.constraint_name,c.constraint_type,cc.column_name  

  from   user_constraints   c,user_cons_columns   cc  

  where   c.owner='DEV_MST'  

  and   c.table_name ='ITEM_MASTER'  

  and   c.owner=cc.owner  

  and   c.constraint_name=cc.constraint_name  

  and   c.constraint_type   in   ('P','U')  

  order   by   c.constraint_type,c.constraint_name,cc.position;  

  

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8058892/viewspace-752637/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: oracle retail
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2011-05-12

  • 博文量
    5
  • 访问量
    7996