how to get informations about relationship of tables in oracle?

jalal rasooly

i need to get information about relationship of tables in following format:

source_table    source_pk    source_fk    destination_table    destination_pk
............    .........    .........    .................    ..............

 employees     employee_id    job_id            jobs               job_id

it says table 'employees' with primary key of 'employee_id' and foreign key of 'job_id' refer to table 'jobs' with primary key of 'job_id'. is there any query to give me this information? update: i want a query that fill this table with all relationships of a particular schema like 'hr'.

San

You can query any of dba_constraints, all_constraints or user_constraints views based on your access level as follows

WITH tab AS (SELECT table_name, 
                    MIN(decode(constraint_type, 'P', constraint_name, NULL)) PRIMARY_KEY, 
                    MIN(decode(constraint_type, 'R', constraint_name, NULL)) FOREIGN_KEY,
                    MIN(decode(constraint_type, 'R', r_constraint_name, NULL)) DESTINATION_PK
               FROM dba_Constraints
              WHERE table_name = 'EMPLOYEE'
              GROUP BY table_name)
SELECT t.table_name, t.PRIMARY_KEY, t.FOREIGN_KEY, uc.table_name, t.DESTINATION_PK
  FROM tab t
  LEFT OUTER JOIN dba_Constraints uc 
    ON (uc.constraint_name = t.destination_pk);

To get information about all tables in particular schema(example HR):

WITH tab AS (SELECT table_name, 
                    MIN(decode(constraint_type, 'P', constraint_name, NULL)) PRIMARY_KEY, 
                    MIN(decode(constraint_type, 'R', constraint_name, NULL)) FOREIGN_KEY,
                    MIN(decode(constraint_type, 'R', r_constraint_name, NULL)) DESTINATION_PK
               FROM all_constraints
              WHERE owner = 'HR'
              GROUP BY table_name)
SELECT t.table_name, t.PRIMARY_KEY, t.FOREIGN_KEY, uc.table_name, t.DESTINATION_PK
  FROM tab t
  LEFT OUTER JOIN all_constraints uc 
    ON (uc.constraint_name = t.destination_pk)
ORDER BY 1;

Note: If there are no primary key on a table, no rows will be returned.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get more informations about this device?

From Dev

How get information about tables in SQL Server?

From Dev

how to get the third properties from many to many relationship tables?

From Dev

How to get sum value from one to many relationship tables?

From Dev

How can I get informations within code about the cache of my app?

From Dev

How to get relationship inside a relationship

From Dev

How to get the list of external tables in oracle schema 11g

From Dev

Database change notification - how get notified of changes in Oracle tables

From Java

Get list of all tables in Oracle?

From Dev

How to get the label of a relationship

From Dev

Entity Relationship Diagram. How does the IS A relationship translate into tables?

From Dev

How to create relationship between two tables with UCanAccess?

From Dev

How to join multiple tables without relationship

From Dev

How to insert data into 2 tables with relationship

From Dev

How to create a new table for relationship between these tables

From Dev

How to choose a relationship for tables in Laravel 5.2?

From Dev

How to JOIN tables in many-to-many relationship

From Dev

How to check eloquent relationship between two tables?

From Dev

How to set relationship between two tables in SQLAlchemy?

From Dev

Get information about schema, tables, primary keys

From Dev

How to retrieve informations about journals from ISI Web of Knowledge?

From Dev

Objective-C/ALAssetLibrary - How read and save informations about images

From Dev

How to preserve informations about original observable on RxJava2

From Dev

How to design an Info-Screen filled with detailed informations about an object

From Dev

How to determine tables size in Oracle

From Dev

How to find Oracle SYSTEMDB Tables

From Dev

How to export empty tables in oracle

From Dev

How get informations of antivirus installed on smartphone?

From Dev

How to get access to relationship field?

Related Related

  1. 1

    How to get more informations about this device?

  2. 2

    How get information about tables in SQL Server?

  3. 3

    how to get the third properties from many to many relationship tables?

  4. 4

    How to get sum value from one to many relationship tables?

  5. 5

    How can I get informations within code about the cache of my app?

  6. 6

    How to get relationship inside a relationship

  7. 7

    How to get the list of external tables in oracle schema 11g

  8. 8

    Database change notification - how get notified of changes in Oracle tables

  9. 9

    Get list of all tables in Oracle?

  10. 10

    How to get the label of a relationship

  11. 11

    Entity Relationship Diagram. How does the IS A relationship translate into tables?

  12. 12

    How to create relationship between two tables with UCanAccess?

  13. 13

    How to join multiple tables without relationship

  14. 14

    How to insert data into 2 tables with relationship

  15. 15

    How to create a new table for relationship between these tables

  16. 16

    How to choose a relationship for tables in Laravel 5.2?

  17. 17

    How to JOIN tables in many-to-many relationship

  18. 18

    How to check eloquent relationship between two tables?

  19. 19

    How to set relationship between two tables in SQLAlchemy?

  20. 20

    Get information about schema, tables, primary keys

  21. 21

    How to retrieve informations about journals from ISI Web of Knowledge?

  22. 22

    Objective-C/ALAssetLibrary - How read and save informations about images

  23. 23

    How to preserve informations about original observable on RxJava2

  24. 24

    How to design an Info-Screen filled with detailed informations about an object

  25. 25

    How to determine tables size in Oracle

  26. 26

    How to find Oracle SYSTEMDB Tables

  27. 27

    How to export empty tables in oracle

  28. 28

    How get informations of antivirus installed on smartphone?

  29. 29

    How to get access to relationship field?

HotTag

Archive