How to discover the underlying primary (or unique) key columns from an Oracle view

前端 未结 2 823
时光说笑
时光说笑 2021-01-03 06:48

I was wondering whether there is a possibility for me to discover the underlying primary (or unique) key columns for all tables involved in an Oracle view. Here\'s an exampl

2条回答
  •  悲哀的现实
    2021-01-03 07:40

    SELECT column_name FROM user_ind_columns
      WHERE index_name =
       (SELECT index_name FROM user_constraints
          WHERE constraint_type='P' AND table_name='T_A')
    ORDER BY column_position;
    

    If you want to do it for all tables that a view depends on, then change the condition on table_name to something like:

    table_name IN (SELECT referenced_name FROM user_dependencies
                     WHERE name='view_name' AND referenced_type='TABLE')
    

提交回复
热议问题