Finding out the metadata and joins

database-designoracle

Suppose I have a database with a large number of tables.

  • Is there any command that I can type in PL/SQL which display only the field names of a given table?
  • Given any table is there any command that I can type that would show all the relations that it has with other tables?

For example , I have a table "TAB_1" , can I type a command that would show all the tables related to and for any table "TAB_2" that it is related to it would show which field in "TAB_1" corresponds to which field in "TAB_2 " .

Best Answer

You can query the system views and look at metadata.

You will get a list of tables using this view:

For a list of columns, you can join the TABLES list with the column views:

There are similar views for:

You can then join some of them and write such a query for a list of columns involved in referential integrity contraints:

SELECT ...
FROM SYS.ALL_CONS_COLUMNS col
JOIN SYS.ALL_CONSTRAINTS con con ON col.owner = con.owner AND col.constraint_name = con.constraint_name
JOIN SYS.ALL_CONS_COLUMNS fk on fk.owner = con.owner and fk.r_constraint_name = con.constraint_name
WHERE con.constraint_type = 'R' AND col.table_name = '...'

With R being (referential integrity) for constraint_type.