Thursday, December 08, 2011

How to find Primary Key of a table

 

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 = 'TABLENAME'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cols.owner = 'sivaora'
AND cons.owner = 'sivaora'
ORDER BY cols.table_name, cols.position


This can be useful when getting error
ORA-00001: unique constraint (constraint_name) violated

No comments: