1-- Primary key in a table
2SELECT * FROM ALL_CONSTRAINTS -- or DBA_CONSTRAINTS or UESR_CONSTRAINTS
3WHERE TABLE_NAME= 'table_name' AND CONSTRAINT_TYPE = 'P';
4-- With columns names:
5SELECT c.OWNER, c.TABLE_NAME, c.CONSTRAINT_NAME, c.CONSTRAINT_TYPE,
6 col.COLUMN_NAME
7FROM ALL_CONSTRAINTS c
8JOIN ALL_CONS_COLUMNS col ON c.TABLE_NAME = col.TABLE_NAME
9 AND c.CONSTRAINT_NAME = col.CONSTRAINT_NAME
10WHERE c.TABLE_NAME= 'table_name' AND c.CONSTRAINT_TYPE = 'P'
11ORDER BY c.TABLE_NAME, c.CONSTRAINT_NAME, col.COLUMN_NAME;
1SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
2FROM all_constraints cons, all_cons_columns cols
3WHERE cols.table_name = 'TABLE_NAME'
4AND cons.constraint_type = 'P'
5AND cons.constraint_name = cols.constraint_name
6AND cons.owner = cols.owner
7ORDER BY cols.table_name, cols.position;