Solved

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

Posted on 2015-01-13
5
437 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
  • 2
  • 2
5 Comments
 
LVL 76

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 34

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 76

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now