Home » SQL & PL/SQL » SQL & PL/SQL » ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated (11g, 11.2.0.1, window7)
ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638092] Tue, 02 June 2015 03:55 Go to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Dear All,

Please let me know, even if I am using "ENABLE NOVALIDATE" on script of primary key creation, below error is occurring.

C:\Windows\system32>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 2 14:11:18 2015

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> alter table tagicrm.CNFGTR_RISK_GRID_DETAIL_TAB
  2  add constraint PK_RISK_GRID primary key (NUM_REFERENCE_NUMBER,DAT_REFERENCE_DATE, SEQ_NO, BLK_ID)
  3  using index
  4  tablespace INS
  5  enable novalidate;
add constraint PK_RISK_GRID primary key (NUM_REFERENCE_NUMBER,DAT_REFERENCE_DATE, SEQ_NO, BLK_ID)
               *
ERROR at line 2:
ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated



Please suggest what can be done to implement the primary key on it, without deleting the records.

Regards,
Ashish Kumar Mahanta
Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638093 is a reply to message #638092] Tue, 02 June 2015 03:58 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
Make it deferrable. It's trying to build you a unique index.
Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638094 is a reply to message #638093] Tue, 02 June 2015 04:01 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
Create a non unique index on the PK Columns, then try again.
Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638095 is a reply to message #638092] Tue, 02 June 2015 04:03 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Note that lying Oracle saying you have a PK when you have is not a good idea.
Oracle uses this information to build execution plan and you may have some performances issues and maybe even wrong result.

Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638096 is a reply to message #638095] Tue, 02 June 2015 04:11 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
Michel Cadot wrote on Tue, 02 June 2015 10:03

Note that lying Oracle saying you have a PK when you have is not a good idea.
Oracle uses this information to build execution plan and you may have some performances issues and maybe even wrong result.




I think, not tested, that it'll behave well enough because it's not been created as RELY. Rely...well, all bets are off.
Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638109 is a reply to message #638096] Tue, 02 June 2015 07:25 Go to previous messageGo to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Dear All,

I tried using "RELY" but got the same error. Now in production we cannot delete the records. So any other help?

Regards,
Ashish
Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638112 is a reply to message #638109] Tue, 02 June 2015 08:07 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

RELY has nothing to do with your error.
The solution has been given: pre-create a non-unique index.

[Updated on: Tue, 02 June 2015 08:08]

Report message to a moderator

Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638113 is a reply to message #638109] Tue, 02 June 2015 08:13 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
True solution would be taking care of duplicate keys and then creating PK with VALIDATE. If NOVALIDATE is justified, then you must follow pablolee's suggestion:

1.Create non-unique index on NUM_REFERENCE_NUMBER,DAT_REFERENCE_DATE, SEQ_NO, BLK_ID
2. Create PK with NOVALIDATE

But keep in mind, you are trading unique for a non-unique index, so there might be some performance cost.

SY.
Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638114 is a reply to message #638113] Tue, 02 June 2015 08:18 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

I remember T. Kyte once said (on AskTom) there is no difference in performances between a unique and a non-unique index.
I will try to find the topic for reference.

Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638117 is a reply to message #638114] Tue, 02 June 2015 14:36 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
THe only difference I am aware of is that there is always one extra block read when using a predicate on a non-unique index. Even if you define a unique constraint, Oracle always checks the next leaf block of the index as well as the block containing the key you want, presumably to be sure that there isn't another matching key. I've tested this a few times, on releases up to 12.1.0.2

In general, I always use non-unique indexes, so that if necessary I can disable the constraint without dropping the index.
Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638118 is a reply to message #638117] Tue, 02 June 2015 15:13 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Right, we are trading unique scan for range scan.

SY.
Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638259 is a reply to message #638118] Mon, 08 June 2015 07:30 Go to previous messageGo to next message
mnitu
Messages: 159
Registered: February 2008
Location: Reims
Senior Member
See also Richard Foote's blog for a detailed discussion on this subject and his conclusions: https://richardfoote.wordpress.com/2007/12/18/differences-between-unique-and-non-unique-indexes-part-i/
Re: ORA-02437: cannot validate (TAGICRM.PK_RISK_GRID) - primary key violated [message #638260 is a reply to message #638259] Mon, 08 June 2015 07:36 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
This poster seems to be a write once & return never to this forum.
Previous Topic: SQL query help
Next Topic: ORA-30036 while running a Procedure
Goto Forum:
  


Current Time: Thu Apr 25 09:22:38 CDT 2024