LoginSignup
6
4

More than 5 years have passed since last update.

Oracle DBの全テーブル名とそのPKを取得するSQL

Last updated at Posted at 2015-05-16

接続しているデータベースで有効な全テーブルの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;
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4