Oracle 中利用系统表来查询约束关系

Primary key and Foreign key

SQL Statement as follows:

select c.CONSTRAINT_name,
       c.Table_NAME,
       l.COLUMN_NAME,
       l.position,
       ‘FK’ as type

 from sys.ALL_CONSTRAINTS c, sys.ALL_CONS_COLUMNS l

 where c.CONSTRAINT_name = l.CONSTRAINT_name
     
   and c.CONSTRAINT_TYPE = ‘R’
     
   and c.owner = ‘SNRC’
     
   and c.Table_NAME not like ‘BIN%’

union

select c.CONSTRAINT_name,
       c.Table_NAME,
       l.COLUMN_NAME,
       l.position,
       ‘PK’ as type

 from sys.ALL_CONSTRAINTS c, sys.ALL_CONS_COLUMNS l

 where c.CONSTRAINT_name = l.CONSTRAINT_name
     
   and c.CONSTRAINT_TYPE = ‘P’
     
   and c.owner = ‘SNRC’
     
   and c.Table_NAME not like ‘BIN%’;

By Lu Jun

80后男,就职于软件行业。习于F*** GFW。人生48%时间陪同电子设备和互联网,美剧迷,高清视频狂热者,游戏菜鸟,长期谷粉,临时果粉,略知摄影。

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.