Solved

Oracle : How to identify columns involved in a Table for Unique Constraint Exception ?

Posted on 2015-01-13
5
477 Views
Last Modified: 2015-01-13
Oracle : How to identify columns involved in a Table for Unique Constraint Exception ?

While trying to Insert, I am getting Exception as

ORA-00001: unique constraint (Table) violated.

Without dropping the Unique Constraint, Is it possible to Insert ?

Is there any way to Turn ON or OFF the Constraint.
0
Comment
Question by:chokka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40547340
>>Oracle : How to identify columns involved in a Table for Unique Constraint Exception ?

Look in user_cons_columns for the CONSTRAINT_NAME.

select * from user_cons_columns where constraint_name='SOME_NAME';

where SOME_NAME is the constraint name in question.

>>Without dropping the Unique Constraint, Is it possible to Insert ?

Not without resolving the violation.  Constraints can be deferrable in that they are not checked until COMMIT.

>>Is there any way to Turn ON or OFF the Constraint.

You can 'disable' it but see above:  You would need to resolve the conflict before it was enabled again.  AND once disabled, all sorts of other 'bad' data can sneak in!
0
 
LVL 35

Accepted Solution

by:
johnsone earned 250 total points
ID: 40547469
You actually can add a record to the table that violates the constraint.

I HIGHLY RECOMMEND THAT YOU DO NOT DO IT  But, it is possible.

Disable the constraint.  Add the invalid record, then re-enable the constraint with ENABLE NOVALIDATE.  This will put the constraint back for new rows, but not check old rows.

The bad...

Other bad data can get in withthe constraint is disabled.
If any row that violates the constraint is updated, you will get the ORA-00001 back.
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 total points
ID: 40547479
>>I HIGHLY RECOMMEND THAT YOU DO NOT DO IT  

I would recommend that you FORGET this was even posted.

>>The bad...

In addition:
The constraint was put there for a reason.  Having data in a table that violates the constraint can have catastrophic implications for applications that rely on the constraint being there and VALID.
0
 

Author Comment

by:chokka
ID: 40547495
slightwv and Johnsonone , Thank you for your suggestion.

I will not disable or remove the constraint.


Thank you. This post is closed. Please dont comment further.

I have some issue with my browser and so, i am not able to Accept Solution option. I will do it later.
0
 

Author Closing Comment

by:chokka
ID: 40548171
Thank you !!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to recover a database from a user managed backup

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question