Solved

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

Posted on 2015-01-13
5
466 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 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 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 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Read about achieving the basic levels of HRIS security in the workplace.
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

828 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