接続しているデータベースで有効な全テーブルのPKを取得するSQL(Oracle限定)。
select t1.table_name, t1.column_name
from user_cons_columns t1
where t1.constraint_name in (
select t2.constraint_name
from user_constraints t2
where t2.table_name in (
select t3.table_name from user_tables t3 where t3.status = 'VALID')
and t2.constraint_type = 'P')
order by t1.table_name, t1.position;