Friday, 23 May 2014


Check FK,PK and CK in Oracle for the specified table


/* foreign keys */

SELECT a.table_name,
       a.column_name,
       a.constraint_name,
       c.owner
  FROM ALL_CONS_COLUMNS A, ALL_CONSTRAINTS C
 WHERE     A.CONSTRAINT_NAME = C.CONSTRAINT_NAME
       AND a.table_name = 'xxxxx'
       AND C.CONSTRAINT_TYPE = 'R';

/* primary keys */

SELECT a.table_name,
       a.column_name,
       a.constraint_name,
       c.owner
  FROM ALL_CONS_COLUMNS A, ALL_CONSTRAINTS C
 WHERE     A.CONSTRAINT_NAME = C.CONSTRAINT_NAME
       AND a.table_name = 'xxxxx'
       AND C.CONSTRAINT_TYPE = 'P';


/* check constraint */

SELECT a.table_name,
       a.column_name,
       a.constraint_name,
       c.owner
  FROM ALL_CONS_COLUMNS A, ALL_CONSTRAINTS C
 WHERE     A.CONSTRAINT_NAME = C.CONSTRAINT_NAME
       AND a.table_name = 'xxxxx'
       AND C.CONSTRAINT_TYPE = 'C';

No comments:

Post a Comment