How to get primary key column in Oracle?

后端 未结 5 1750
悲哀的现实
悲哀的现实 2020-11-29 17:12

I need to get the name of the primary key column.

In the input, I only have the table name.

5条回答
  •  死守一世寂寞
    2020-11-29 17:38

    Save the following script as something like findPK.sql.

    set verify off
    accept TABLE_NAME char prompt 'Table name>'
    
    SELECT cols.column_name
    FROM all_constraints cons NATURAL JOIN all_cons_columns cols
    WHERE cons.constraint_type = 'P' AND table_name = UPPER('&TABLE_NAME');
    

    It can then be called using

    @findPK
    

提交回复
热议问题