Pregunta

I want to check if film.language_id refers to language.language_id. I used the code:

SELECT *
FROM all_tab_columns
WHERE column_name = 'film.language';

Result:

no rows selected

Does this mean there are no references/referential constraints?

¿Fue útil?

Solución

If you want to find out if a column refers to another column by foreign key constraint you can do the following:

Find out if the column is in a constraint:

select constraint_name from user_cons_columns
where table_name='<Your_table>'
and column_name='<Your_column>';

If it is this will give you the name of that constraint. Next you can find out if that constraint is a foreign key constraint and where the foreign key points to:

select constraint_type
      ,r_constraint_name
  from user_constraints
 where constraint_name='<your constraint name>';

If the constraint is a foreign key constraint it is of type 'R'. This will also give you the name of the primary key constraint the foreign key relates to.

Given the name of the primary key constraint you can find the table and column(s) as follows:

select table_name
      ,column_name
  from user_cons_columns
 where constraint_name = 'Your PK constraint'

To make life easier you can join all these queries together. But I leave that to you.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top