Verify conditions before creating a constraint
You can find duplicate PKs: 

select pk_col, count(*)
from tab
group by pk_col
having count(*) &gt; 1 -- multiple rows with the same PK exist


Or the actual rows violating the PK:

select * from tab
where pk_col in 
 (
   select pk_col
   from tab
   group by pk_col
   having count(*) &gt; 1 -- multiple rows with the same PK exist
 )


This returns bad FKs:

select * from child_tab as c
where not exists  -- invalid values in FK column
 (
   select * from parent_tab as p
   where c.fk_col = p.pk_col
 )


Now you can fix the bad data before you add the constraint.