Monday, June 6, 2016

Ghost Constraints in Oracle

When you drop/update constraints in Oracle, specially as I had to update a unique constraint in a table, First I updated the constraint and tried to insert a raw in to the table with the updated unique constraints. Then I noticed, it is throwing an error by applying the old constraint. I was wondering and dropped the constraint and tried again to insert the raw. Then also it was the same error.

As it was strange, I tried to find a solution. Then I got to know that Oracle has an index created with the same name of the unique constraint dropped/updated.

select index_name 
from user_indexes
where table_name = '--insert the table name here--'
and  uniqueness='UNIQUE' 
/

You can verify it using the above query. Then I dropped the index using the below query and re applied the unique constraint as I wanted, Now the raw is successfully inserted in to the table.

DROP INDEX --insert the constraint name here--
/
Thanks for the below link on the solution

http://stackoverflow.com/questions/2372163/finding-ghost-constraint-from-oracle-db