Saturday, 2 February 2013

How to get primary key column in Oracle?

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