Tuesday, 30 July 2013

How to get primary key column in Oracle?

Step 1:
 
Create sample table with one of the column defined as primary key constraint
 
Step 2:
 
Execute following command :
SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
FROM ALL_CONSTRAINTS cons, ALL_CONS_COLUMNS cols
WHERE cols.table_name = 'TABLE_NAME'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.table_name, cols.position;


:):)  Enjoy

No comments:

Post a Comment