oracle list primary key

Solutions on MaxInterview for oracle list primary key by the best coders in the world

showing results for - "oracle list primary key"
Nala
05 Nov 2018
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;