Friday, May 27, 2011

Finding the primary keys for a table

SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
FROM all_constraints cons, all_cons_columns cols
WHERE cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
and upper(cons.constraint_name) = 'SYS_C009448' --name of the constarint that got violated

ORDER BY cols.table_name, cols.position;

No comments: