Unique Key Violation error while updating table

Hi All,
I am having problem with UNIQUE CONSTRAINT. I am trying to update a table and getting the violation error. Here is the over view. We have a table called ActivityAttendee. ActivityAttendee has the following columns. The problem to debug is this table has
over 23 million records. How can I catch where my query is going wrong?
ActivityAttendeeID INT PRIMARY KEY IDENTITY(1,1)
,ActivityID INT NOT NULL (Foreign key to parent table Activity)
,AtendeeTypeCodeID INT NOT NULL
,ObjectID INT NOT NULL
,EmailAddress VARCHAR(255) NULL
UNIQUE KEY is on ActivityID,AtendeeTypeCodeID,ObjectID,EmailAddress
We have a requirement where we need to update the ObjectID. There is a new mapping where I dump that into a temp table #tempActivityMapping (intObjectID INT NOT NULL, intNewObjectID INT NULL)
The problem is ActivityAttendee table might already have the new ObjectID and the unique combination.
For example: ActivityAttendee Table have the following rows
1,1,1,1,NULL
2,1,1,2,NULL
3,1,1,4,'abc'
AND the temp table has 2,1
So essentially when I update in this scenario, It should ignore the second row because, if I try updating that there will be a violation of key as the first record has the exact value. When I ran my query on test data it worked fine. But for 23 million records,
its going wrong some where and I am unable to debug that. Here is my query
UPDATE AA
SET AA.ObjectID = TMP.NewObjectID
FROM dbo.ActivityAttendee AA
INNER JOIN #tmpActivityMapping TMP ON AA.ObjectID = TMP.ObjectID
WHERE TMP.NewObjectID IS NOT NULL
AND NOT EXISTS(SELECT 1
FROM dbo.ActivityAttendee AA1
WHERE AA1.ActivityID = AA.ActivityID
AND AA1.AttendeeTypeCodeID = AA.AttendeeTypeCodeID
AND AA1.ObjectID = TMP.NewObjectID
AND ISNULL(AA1.EmailAddress,'') = ISNULL(AA.EmailAddress,'')

>> I am having problem with UNIQUE CONSTRAINT. I am trying to update a table and getting the violation error. Here is the over view. We have a table called Activity_Attendee. <<
Your problem is schema design. Singular table names tell us there is only one of them the set. Activities are one kind of entity; Attendees are a totally different kind of entity; Attendees are a totally different kind of entity. Where are those tables? Then
they can have a relationship which will be a third table with REFERENCES to the other two. 
Your table is total garbage. Think about how absurd “attendee_type_code_id” is. You have never read a single thing about data modeling. An attribute can be “attendee_type”, “attendee_code” or “attendee_id”but not that horrible mess. I have used something like
this in one of my busk to demonstrate the wrong way to do RDBMS as a joke, but you did it for real. The postfix is called an attribute property in ISO-11179 standards. 
You also do not know that RDBMS is not OO. We have keys and not OIDs; but bad programmers use the IDENTITY table property (NOT a column!), By definition, it cannot be a key; let me say that again, by definition. 
>> ActivityAttendee has the following columns. The problem to debug is this table has over 23 million records [sic: rows are not records]<<
Where did you get “UNIQUE KEY” as syntax in SQL?? What math are you doing the attendee_id? That is the only reason to make it INTEGER. I will guess that you meant attendee_type and have not taken the time to create an abbreviation encoding it.
The term “patent/child” table is wrong! That was network databases, not RDBMS. We have referenced and referencing table. Totally different concept! 
CREATE TABLE Attendees
(attendee_id CHAR(10) NOT NULL PRIMARY KEY, 
 attendee_type INTEGER NOT NULL  --- bad design. 
    CHECK (attendee_type BETWEEN ?? AND ??), 
 email_address VARCHAR(255), 
CREATE TABLE Activities
(activity_id CHAR(10) NOT NULL PRIMARY KEY, 
Now the relationship table. I have to make a guess about the cardinally be 1:1, 1:m or n:m. 
CREATE TABLE Attendance_Roster
(attendee_id CHAR(10) NOT NULL --- UNIQUE??
   REFERENCES Attendees (attendee_id), 
 activity_id Activities CHAR(10) NOT NULL ---UNIQUE?? 
  REFERENCES Activities (activity_id)
 PRIMARY KEY (attendee_id, activity_id), --- wild guess! 
>> UNIQUE KEY is on activity_id, attendee_type_code_id_value_category, object_id, email_address <<
Aside from the incorrect “UNIQUE KEY” syntax, think about having things like an email_address in a key. This is what we SQL people call a non-key attribute. 
>> We have a requirement where we need to update the ObjectID. There is a new mapping where I dump that into a temp table #tempActivityMapping (intObjectID INTEGER NOT NULL, intNewObjectID INTEGER NULL) <<
Mapping?? We do not have that concept in RDBMS. Also putting meta data prefixes like “int_” is called a “tibble” and we SQL people laugh (or cry) when we see it. 
Then you have old proprietary Sybase UODATE .. FROM .. syntax. Google it; it is flawed and will fail. 
Please stop programming until you have a basic understanding of RDBMS versus OO and traditional file systems. Look at my credits; when I tell you, I think I have some authority. 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • ERROR WHILE UPDATING TABLE 'COBK'

    DEAR ALL!
    I am facing the following error while posting goods issue through VL01N and stock posting through MB1C ( m.type 521 without production order ).
    Table COBK is not updated wile doing those trasactions, this cause the runtime error.how to solve this issue?
    I searched SAP notes but problem not yet solved.Kindly go through the following error and give your suggestions.
    Thanks in advance.
    Error analysis
    An exception occurred. This exception is dealt with in more detail below
    . The exception, which is assigned to the class 'CX_SY_OPEN_SQL_DB', was
    neither
    caught nor passed along using a RAISING clause, in the procedure
    "INSERT_TABLES" "(FORM)"
    Since the caller of the procedure could not have expected this exception
    to occur, the running program was terminated.
    The reason for the exception is:
    If you use an ABAP/4 Open SQL array insert to insert a record in
    the database and that record already exists with the same key,
    this results in a termination.
    (With an ABAP/4 Open SQL single record insert in the same error
    situation, processing does not terminate, but SY-SUBRC is set to 4.)
    Sivasubramaniam,
    SD consultant.

    I am pretty sure table COBK is a the Cost Center Accounting table.
    You need to get your Finance consultant to check the periods and years are open in CCA. In fact check that they want to post to CCA.
    Also check the number ranges have been set up correctly for the type of postings.
    Please award points if this is useful.

  • Error while updating table in database.

    Hi,
    While updating a table I came across following error-
    ORA-01552: cannot use system rollback segment for non-system tablespace 'USERS'
    I have following undo parameters set in my parameter file-
    undo_management=auto
    undo_tablespace=UNDOTBS1
    If I have seperate undo tablespace then why Oracle is trying to use System undo segments?
    Thanks,

    Let's assume your settings are correct. However the error means you don't have an UNDO tablespace available. It could be because your tablespace doesn't exist, or you think you have started up your instance with this initialization parameter file.
    You should make sure you have your undo tablespace attached to your database, and you are using your correct initialization file.
    Have you edited this parameter in your pfile? Or have you configured this parameter in you spfile?
    Issue a query against v$rollname, you should see something simmilar to this:
    SQL> SELECT * FROM V$ROLLNAME;
    USN NAME
    0 SYSTEM
    1 _SYSSMU1$
    2 _SYSSMU2$
    3 _SYSSMU3$
    4 _SYSSMU4$
    5 _SYSSMU5$
    6 _SYSSMU6$
    7 _SYSSMU7$
    8 _SYSSMU8$
    9 _SYSSMU9$
    10 _SYSSMU10$
    If you can't then definitely you are not starting up your database with undo segments.

  • Error while updating table before branching to a report

    Hi,
    I have an apex form screen where on click of a button, i need to change a few flags on the screen and then display a bi publisher report.
    when the user clicks the PRINT Button a javascript function is called, which will set the flags and submits the form. I have the default process row of table process to update the form fields.
    in the branch i gave the BI publisher report url.
    everything works fine so far.
    if i click the print button again for a second time, i get a checksum ... error as shown below.
    ORA-20001: Error in DML: p_rowid=982-000790, p_alt_rowid=_ID_NUMBER, p_rowid2=, p_alt_rowid2=. ORA-20001: Current version of data in database has changed since user initiated update process. current checksum = "BD63FDD3142B79017CCD2C8DA8ED8CA7" application checksum = "B2FD7581A9478214E59264F9C1CFAF96"
    Error Unable to process row of table .
    OK
    Any idea how to fix this?
    What i am trying to do is:
    when the print button is clicked then i need to set the Print flag in the screen and database to true.I am using the default row update process generated by apex for a table form.
    Thanks
    Knut

    Hi Scott,
    example 1
    I have a demo at the following url
    http://apex.oracle.com/pls/otn/f?p=30091:6:1206476651563662::NO:::
    1. page 6 is the report and page 7 will be the details form.
    2. select a record from the report click edit and it will take you to the details screen page 7.
    3. on page 7 i have 2 select boxes with YES/NO flag. Initially set them to NO.
    save changes.
    4. click on the print button. it will reset the select lists to YES and opens a report.
    5.now go and edit anything on the screen and click apply changes.
    we will get the an error.
    All i am trying to do is update the flags to YES before displaying the report which works fine. but if i try to edit any data and save it throws an error.
    is my table.
    CREATE TABLE "DEMO_MINISTER"
    (     "MINISTER_ID" VARCHAR2(12),
         "NAME" VARCHAR2(50),
         "CERT_FLAG" VARCHAR2(1),
         "LABEL_FLAG" VARCHAR2(1)
    MINISTER_ID" is the primary key generated using a sequence. (i have to actually generate it with - year prefix etc hence a varchar)
    example 2:
    http://apex.oracle.com/pls/otn/f?p=30091:1:607292687304632:::::
    i have another page page 1 with demo_customers list. here the id is a number here. on edit it displays page 5 where i tried the same print reset flag stuff here and it works.
    Table Data Indexes Model Constraints Grants Statistics UI Defaults Triggers Dependencies SQL
    CREATE TABLE "DEMO_CUSTOMERS"
    (     "CUSTOMER_ID" NUMBER NOT NULL ENABLE,
         "CUST_FIRST_NAME" VARCHAR2(20) NOT NULL ENABLE,
         "CUST_LAST_NAME" VARCHAR2(20) NOT NULL ENABLE,
         "CUST_STREET_ADDRESS1" VARCHAR2(60),
         "CUST_STREET_ADDRESS2" VARCHAR2(60),
         "CUST_CITY" VARCHAR2(30),
         "CUST_STATE" VARCHAR2(2),
         "CUST_POSTAL_CODE" VARCHAR2(10),
         "PHONE_NUMBER1" VARCHAR2(25),
         "PHONE_NUMBER2" VARCHAR2(25),
         "CREDIT_LIMIT" NUMBER(9,2),
         "CUST_EMAIL" VARCHAR2(30),
         "PRINT_FLAG" VARCHAR2(1),
         "PRINT_LABEL_FLAG" VARCHAR2(1),
         CONSTRAINT "DEMO_CUST_CREDIT_LIMIT_MAX" CHECK (credit_limit <= 5000) ENABLE,
         CONSTRAINT "DEMO_CUSTOMERS_PK" PRIMARY KEY ("CUSTOMER_ID") ENABLE
    So what should i do to get the example 1 to work.
    Thanks
    knut

  • Error while updating table

    Hi,
    I am using oracle 11g db.
    Trying to update one of my table using following query :
    UPDATE EMPLOYEE_HISTORY_ALL_T TMDC
    SET LAST_UPDATE_DATE = '01-apr-1901'
    WHERE EXISTS
    (SELECT 1
    FROM PROJECT_T TMP
    WHERE TMP.PROJECT_ID = TMDC.PROJECT_ID
    AND NVL(TMP.COL_CHG_DATE, TO_DATE('01-apr-1901', 'dd-mon-yyyy')) >= '01-apr-1901')
    AND FIRST_PROCESS_DATE >= '01-apr-1901';
    Error comes like "Table or view doesn't exist". Table is in the same schema in which I am trying this update stmt.
    Also when I do Select * from this table data is coming.
    In the all_objects I can see there is public synonym also with the same name. I think while updating it is refering to that synonym instead of table , so error is coming.
    please tell me how can I refer to table in this case and not the synonym.

    For table EMPLOYEE_HISTORY_ALL_T
    OWNER     OBJECT_NAME     SUBOBJECT_NAME     OBJECT_ID     DATA_OBJECT_ID     OBJECT_TYPE     CREATED     LAST_DDL_TIME     TIMESTAMP     STATUS     TEMPORARY     GENERATED     SECONDARY     NAMESPACE     EDITION_NAME
    PUBLIC     EMPLOYEE_HISTORY_ALL_T          726992          SYNONYM     11/15/2011 6:17:37 PM     11/15/2011 6:17:37 PM     2011-11-15:18:17:37     VALID     N     N     N     1     
    MIS     EMPLOYEE_HISTORY_ALL_T          726988     1752101     TABLE     2/23/2007 10:18:18 PM     11/15/2011 6:19:44 PM     2011-11-15:18:19:44     VALID     N     N     N     1     
    For table PROJECT_T
         OWNER     OBJECT_NAME     SUBOBJECT_NAME     OBJECT_ID     DATA_OBJECT_ID     OBJECT_TYPE     CREATED     LAST_DDL_TIME     TIMESTAMP     STATUS     TEMPORARY     GENERATED     SECONDARY     NAMESPACE     EDITION_NAME
         PUBLIC     PROJECT_T          35158          SYNONYM     3/1/2006 3:33:23 PM     11/14/2009 4:00:21 PM     2009-11-14:16:00:21     VALID     N     N     N     1     
         BSC     PROJECT_T          35250          SYNONYM     2/25/2006 3:49:46 AM     11/15/2009 1:15:35 PM     2009-11-15:13:15:35     VALID     N     N     N     1     
         CDWSTG     PROJECT_T          37350          SYNONYM     2/25/2006 5:32:32 AM     11/15/2009 11:01:34 AM     2009-11-15:11:01:34     VALID     N     N     N     1     
         CDWPROD     PROJECT_T          40102          SYNONYM     2/25/2006 11:46:03 AM     1/1/2010 3:42:17 PM     2010-01-01:15:42:17     VALID     N     N     N     1     
         MIS     PROJECT_T          810675     7360542     TABLE     4/2/2007 3:30:07 PM     11/11/2011 5:23:55 PM     2009-11-14:15:28:15     VALID     N     N     N     1     
         DEL25PROD     PROJECT_T          645792     1237989     TABLE     1/9/2007 6:28:08 PM     9/6/2009 8:18:13 PM     2007-01-09:18:28:08     VALID     N     N     N     1     
         DELSTG     PROJECT_T          1271755          SYNONYM     11/1/2007 1:54:32 PM     1/1/2010 3:42:17 PM     2010-01-01:15:42:17     VALID     N     N     N     1     
    I am logging through MIS schema. In this schema only I am running the update query.

  • Getting index error while updating table

    Hi All,
    I am getting error
    SQL> UPDATE bqcustomer
    2 SET
    3 namelegal = 'SME ' || SubStr(bqcustomer.namelegal,8),
    4 nameshort = 'SME ' || SubStr(bqcustomer.nameshort,8),
    5 nametrading='SME ' || SubStr(bqcustomer.nametrading,8)
    6 WHERE
    7 hassmeaccount = 1
    8 AND nametrading LIKE 'GLOBAL %' ;
    UPDATE bqcustomer
    ERROR at line 1:
    ORA-08102: index key not found, obj# 60473, dba 46348301 (2)
    any help on this will be appreciated .
    Thanks in advance
    Sachin Srivastava

    ORA-08102 INDEX KEY NO FOUND, OBJ# 25095, DBA 33567643 (2)

  • Mutating Trigger error while updating table

    Hi Guys,
    I am updating one table and after trigger also fire at the same time. Now, I want to avoid mutating trigger error. Can any one help me on this.
    Thanks in advance!
    Regards,
    -LRK

    You'll have to read these articles first, they explain what's the problem and how to deal with it:
    http://www.oracle-base.com/articles/9i/MutatingTableExceptions.php
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551198119097816936
    but, as Saubhik already said, using Oracle's AUDIT functionality would be the way to go.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_4007.htm
    Using an autonomous transaction can result in corrupted data or unexpected errors, stay away from them if you want to use them in order to bypass/hide your mutating table error.

  • Uniques constraint violation error while executing statspack.snap

    Hi,
    I have configured a job to run the statspack snap at a interval of 20 min from 6:00 PM to 3:00 AM . Do perform this task , I have crontab 2 scripts : one to execute the job at 6 PM and another to break the job at 3 AM. My Oracle version is 9.2.0.7 and OS env is AIX 5.3
    My execute scripts look like:
    sqlplus perfstat/perfstat <<EOF
    exec dbms_job.broken(341,FALSE);
    exec dbms_job.run(341);
    The problem is , that the job work fine for weekdays but on weekend get aborted with the error :
    ORA-12012: error on auto execute of job 341
    ORA-00001: unique constraint (PERFSTAT.STATS$SQL_SUMMARY_PK) violated
    ORA-06512: at "PERFSTAT.STATSPACK", line 1361
    ORA-06512: at "PERFSTAT.STATSPACK", line 2471
    ORA-06512: at "PERFSTAT.STATSPACK", line 91
    ORA-06512: at line 1
    After looking on to metalink , I came to know that this is one listed bug 2784796 which was fixed in 10g.
    My question is , why there is no issue on weekdays using the same script. There is no activity on the db on weekend and online backup start quite late at night.
    Thanks
    Anky

    The reasons for hitting this bug are explained in Metalink, "...cursors with same sql text (at least 31 first characters), same hash_value but a different parent cursor...", you can also find the workaround in Note:393300.1.
    Enrique

  • Unique constraint violation error while bulk insert (TimesTen 7.0.1.0.0)

    Hi,
    I try to understand while I get error above when doing bulk inserts via TimesTen into Oracle database.
    The single inserts after that works perfect (no record will dropped), when doing direct to oracle bulk insert works with same data perfect. We tried it with AWT, then with readonly tables and passtrough=2, nothing works. The error comes even the table is empty.
    Any suggestions? is this a bug in timesten itself? Have I connect for bulk inserts direct to oracle database?
    Thanks in advanced
    Rajko Albrecht

    It may be a TT bug but if so it is not an obvious one since bulk inserts definitely work in TimesTen...
    Can you please provide:
    1. The schema of the table in question (including any indices)
    2. Details on how you are doing the bulk inserts (C/ODBC program, Java/JDBC program or ...). Actual program source code would be helpful.
    3. A (small) example of the data that you know would give this error.
    Thanks,
    Chris

  • Unique constraint violation error

    Hello All,
    I have a procedure called - FHM_DASHBOARD_PROC which inserts the data into a table called FHM_DASHBOARD_F fetching records from several tables. However, for a particular type of record, that data is not being inserted because of the Unique constraint violation
    the procedure is:
    create or replace
    PROCEDURE FHM_DASHBOARD_PROC AS
    DB_METRICS_CNT1Z number;
    --V_PODNAME varchar2(10);
    V_KI_CODE_DB_STATSZ varchar2(50);
    V_ERRORSTRING varchar2(100);
    --CURSOR PODNAME_CUR IS SELECT PODNAME,SHORTNAME FROM CRMODDEV.POD_DATA WHERE PODSTATUS_ID=1 AND PODTYPE_ID=1 ORDER BY PODNAME;
    -- DB STATS
    BEGIN
      -- OPEN PODNAME_CUR;
        --   LOOP
          --   FETCH PODNAME_CUR INTO V_PODNAME,V_POD_SHORTNAME ;
            -- EXIT WHEN PODNAME_CUR%NOTFOUND;
               BEGIN
                     SELECT COUNT(*) INTO DB_METRICS_CNT1Z FROM FHM_DB_METRICS_F A, FHM_DB_D B where A.DBNAME=B.DBNAME and PODNAME=V_PODNAME AND DB_DATE=TRUNC(SYSDATE-1);
                               DBMS_OUTPUT.PUT_LINE('DB_METRICS_CNT1Z :'|| DB_METRICS_CNT1Z);
                               IF DB_METRICS_CNT1Z >0 THEN
                        DBMS_OUTPUT.PUT_LINE('DB STATS');
                       INSERT INTO FHM_DASHBOARD_F(PODNAME,DASH_DATE,KI_CODE,KI_VALUE,KI_STATUS)
                          (SELECT PODNAME, DASH_DATE AS CU_DATE, KI.KI_CODE, NVL(PF.KI_VALUE,0),
                                                                  CASE
                                                                   WHEN PF.KI_VALUE = ki.warning_threshold then 2
                        when PF.KI_VALUE=0 then 0
                        ELSE 1
                        END  AS ALERT_STATUS
                        FROM
                        (SELECT PODNAME,DB_DATE AS DASH_DATE,decode(a.stats_last_status,'SUCCEEDED',1,'FAILED',2,'STOPPED',2,NULL,0) KI_VALUE from 
                        FHM_DB_METRICS_F a,fhm_db_d b where a.dbname=b.dbname and podname='XYZ' and db_date=TRUNC(SYSDATE-1) and dbtype='OLTP')PF,
                        FHM_KEY_INDICATOR_D KI where PF.PODNAME=KI.POD_NAME AND KI.TIER_CODE=3 AND KI.KI_NAME='DB_STATS'
                        AND (PF.PODNAME,TRUNC(PF.DASH_DATE),KI.KI_CODE) NOT IN (SELECT PODNAME,DASH_DATE,KI_CODE FROM FHM_DASHBOARD_F));
                                 COMMIT;
                             ELSE
                                    SELECT KI_CODE INTO V_KI_CODE_DB_STATSZ FROM FHM_KEY_INDICATOR_D WHERE POD_NAME=V_PODNAME AND KI_NAME='DB_STATS';
                                     DBMS_OUTPUT.PUT_LINE('V_KI_CODE_DB_STATSZ :'||V_KI_CODE_DB_STATSZ);
                                     INSERT INTO FHM_DASHBOARD_F(PODNAME,DASH_DATE,KI_CODE,KI_VALUE,KI_STATUS) VALUES(V_PODNAME,TRUNC(SYSDATE-1),V_KI_CODE_DB_STATSZ,0,0);
                                     COMMIT;
                             END IF;
         EXCEPTION
                            WHEN OTHERS THEN
                            V_ERRORSTRING :='INSERT INTO FHM_DASHBOARD_F_ERROR_LOG(POD_NAME,KI_NAME,ERRORNO,ERRORMESSAGE,DATETIME) VALUES
                   ('''||V_PODNAME||''',''DB_STATS'','''||SQLCODE||''','''||SQLERRM||''',SYSDATE)';                        
                   EXECUTE IMMEDIATE  V_ERRORSTRING;
                            COMMIT;
              END;
          --END LOOP;
      --CLOSE PODNAME_CUR;
    END;
    END FHM_DASHBOARD_PROC;and the table where the data is inserting is
    CREATE TABLE "CRMODDEV"."FHM_DASHBOARD_F"
        "PODNAME" VARCHAR2(25 BYTE) NOT NULL ENABLE,
        "DASH_DATE" DATE,
        "KI_CODE"   NUMBER NOT NULL ENABLE,
        "KI_VALUE"  NUMBER,
        "KI_STATUS" NUMBER,
        CONSTRAINT "FHM_DASHBOARD_F_DATE_PK" PRIMARY KEY ("DASH_DATE", "PODNAME", "KI_CODE") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CRMODDEV_IDX" ENABLE,
        CONSTRAINT "FHM_DASHBOARD_F_KI_CODE_FK" FOREIGN KEY ("KI_CODE") REFERENCES "CRMODDEV"."FHM_KEY_INDICATOR_D" ("KI_CODE") ENABLE
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS NOLOGGING STORAGE
        INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
      TABLESPACE "CRMODDEV_TBL" ENABLE ROW MOVEMENT ;the Primary key constraint is FHM_DASHBOARD_F_DATE_PK and is on 3 columns of the table DASH_DATE, PODNAME, KI_CODE
    And this is the query used in the Procedure for inserting the data into the table
    (SELECT  PODNAME, DASH_DATE AS CU_DATE, KI.KI_CODE, NVL(PF.KI_VALUE,0),
                                   CASE
                                   WHEN PF.KI_VALUE = ki.warning_threshold then 2
    when PF.KI_VALUE=0 then 0
    ELSE 1
    END  AS ALERT_STATUS
    From
    (Select  Podname,Db_Date As Dash_Date,Decode(A.Stats_Last_Status,'SUCCEEDED',1,'FAILED',2,'STOPPED',2,Null,0) Ki_Value From  -- Added Distinct
    FHM_DB_METRICS_F a,fhm_db_d b where a.dbname=b.dbname and podname in ('XYZ') and db_date = TRUNC(SYSDATE-2) and dbtype='OLTP')PF,
    Fhm_Key_Indicator_D Ki Where Pf.Podname=Ki.Pod_Name And Ki.Tier_Code=3 And Ki.Ki_Name='DB_STATS'
    And (Pf.Podname,Trunc(Pf.Dash_Date),Ki.Ki_Code) Not In (Select Podname,Dash_Date,Ki_Code From Fhm_Dashboard_F));It gives *2 record* as result
    XYZ 20-JAN-12     2521     1     1
    XYZ 20-JAN-12     2521     1     1
    So it gives Unique constraint violation error while inserting. Then, I changed in the above inserting code by adding a distinct clause. After that the query gives only ONE record as result. However, that record also is not being inserted into the table and giving the same error.
    Now the question is How shall I insert this record into the table successfully ?
    Though the message is too long, However, I have given you the full structure of the object/procedure and error.
    Thank You in Advance.

    when you have 5 columns in the result set adding DISTINCT is n ot the solution as you may get the same error again.
    Check the target table whether the data exists before inserting ..if not check the table structure for unique constraint created on other columns.
    select *from <table_name>
    where
    DASH_DATE=date '2012-01-20'
    and PODNAME='XYZ'
    and  KI_CODE=2521;

  • Unique Key Violation While Doing Multiple Updates And Create in EJB

    Hello All,
    I am using oracle 9i and Weblogic 7.0. I have a table that has a unique key constraint on one column , say 'Col1' and i am using a CMP to read,create and update data in this table. The problem description is as follows.
    I have JTable that display the data from the above said table. The user can modify the existing data and insert new data that will be reflected in the DB using the CMP. Let us say the following are displayed
    ROW1
    Col1 : 3
    Col2 : 'ABC'
    Col3 : 1 (Primary key in the table)
    Now the user modifies the above row and inserts a new record. Now the following will be the display
    ROW1 (Modified)
    Col1 : 4
    Col2 : 'ABC'
    Col3 : 1 (Primary key in the table)
    ROW2 (New)
    Col1 : 3
    Col2 : 'DEF'
    Col3 : 2 (Primary key in the table)
    When the above data is saved i do the following in the Code
    a) Session Bean
    For (all the data in the Jtable)
    try
    home.findByPrimaryKey(Col3);
    remote.update(Col1,Col2);
    catch(FinderException fe)
    home.create(Col1,Col2,Col3);
    When the above code is run During the first loop the update runs succesfully (i.e update old value of 3 with 4 ) but during the 2nd loop the create (i.e Insert new value 3) gives me the unique key violated exception. The following is the stack trace
    <Oct 25, 2004 11:36:22 AM IST> <Info> <EJB> <010049> <EJB Exception in method: ejbPostCreate: java.sql.SQLException: ORA-00001: unique constraint (UAT_CYCLE2_1.UK_PYMT_DET_TX) violated
    java.sql.SQLException: ORA-00001: unique constraint (UAT_CYCLE2_1.UK_PYMT_DET_TX) violated
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1892)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2130)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2013)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2869)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
    at weblogic.jdbc.jts.Statement.executeUpdate(Statement.java:509)
    at de.dl.ucs.contract.entity.TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.__WL_create(TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.java:1435)
    at de.dl.ucs.contract.entity.TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.ejbPostCreate(TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.java:1353)
    at java.lang.reflect.Method.invoke(Native Method)
    at weblogic.ejb20.manager.DBManager.create(DBManager.java:1023)
    at weblogic.ejb20.manager.DBManager.localCreate(DBManager.java:904)
    at weblogic.ejb20.internal.EntityEJBLocalHome.create(EntityEJBLocalHome.java:180)
    at de.dl.ucs.contract.entity.TerminalPaymentsCMP_kbdoop_LocalHomeImpl.create(TerminalPaymentsCMP_kbdoop_LocalHomeImpl.java:73)
    at de.dl.ucs.contract.helperclasses.SubsegmentMaintanence.saveTerminalPayments(SubsegmentMaintanence.java:697)
    at de.dl.ucs.contract.controller.SubsegmentSL.saveSubsegmentDetails(SubsegmentSL.java:570)
    at de.dl.ucs.contract.controller.SubsegmentSL.processFinanceSubsegmentSave(SubsegmentSL.java:1601)
    at de.dl.ucs.contract.controller.SubsegmentSL_kgzv4j_EOImpl.processFinanceSubsegmentSave(SubsegmentSL_kgzv4j_EOImpl.java:498)
    at de.dl.ucs.contract.events.FinanceSubsegmentBEH.saveSubsegmentDetails(FinanceSubsegmentBEH.java:749)
    at de.dl.ucs.contract.events.FinanceSubsegmentBEH.processEvent(FinanceSubsegmentBEH.java:232)
    at de.dl.ucs.framework.flowcontroller.ControllerBean.delegateAction(ControllerBean.java:229)
    at de.dl.ucs.framework.flowcontroller.ControllerBean_riqvk4_EOImpl.delegateAction(ControllerBean_riqvk4_EOImpl.java:46)
    at de.dl.ucs.framework.flowcontroller.ControllerBean_riqvk4_EOImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:441)
    at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:382)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:726)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:377)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:234)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:210)
    >
    <Oct 25, 2004 11:36:22 AM IST> <Info> <EJB> <010051> <EJB Exception during invocation from home: [email protected] threw exception: javax.ejb.TransactionRolledbackLocalException: EJB Exception:; nested exception is: java.sql.SQLException: ORA-00001: unique constraint (UAT_CYCLE2_1.UK_PYMT_DET_TX) violated
    Please help me with this, as far as i am concerned since both update and create is in the same transaction the update on the row must be visible to the create and hence there shouild not be any problem.....
    thanks in advance
    Shanki

    Hi,
    Thanks,
    There are 3 columns involved with that table . Out of whihc one is a Primary Key (string) , The other column (Number) has a unique key constraint defined on it and the last column stores a value corresponding to the 2nd column.
    The reason for me to do a create in the Finder exception is as follows.
    I Loop through the Data present in JTable. As given in the example let us assume that there are 2 rows in the JTable. Out of whihc the First row needs an updation and the second row , which is a new row needs to be created. So During the First iteration of the loop, The findermethod does not throw any exception (Because it is a modfied row) and hence the update gets fired successfully. During the second iteration , since it is a new row the findermethod will throw a finder exception and hence create will get fired.
    I understand that this is not a good coding style but then it is not 100% wrong and i need to find out as to why it is not working.
    Hope am clear in explaining my problem
    Thanks
    Shanki

  • Primary Key rule Violation error while Insert Record in Compact DB

    Hi All,
    I have One Table in Server Name "Student"  when i Synchronize this with the help of Microsoft Synchronization Framework
    same Table schema with Data has been create in CompactDataBase.
    When i insert data in CompactDataDase it give me Primary Key Violation error.
    Please Suggest
    Example
    Table Structure is as Follows:-
    Create Table Student(
    [Emp_id] int IDENTITY(1,1) NotNull,[Emp_Name] int NOTNULL );insert into Student Values('John');insert into Student Values('Joe');Thanks & RegardsNamit Jain

    try this and see if it solves,
    also, Emp_name data type is int. it should be varchar.
    I suspect the reason is because you already have some data in student table but you identity seeds were not updated and hence it is trying to insert a row with emp_id value that already exists.and hence the primary key violation. also, your table DDL did
    not really have an primary key but it would still error since you are inserting duplicate row in the identity column.
    so, try resetting the identity seed value to the max(emp_id) in the table.
    select max(Emp_ID) from  student
    --use the output of the above statement
    DBCC CHECKIDENT ('Student', RESEED,<<--use the output of the above statement-->>)
    --your max(emp_id) should match with last_value column in the below( do not if this query would run in compact DB though)
    select seed_value,increment_value,last_value from sys.identity_columns where object_id=object_id('Student')
    now, try your insert.
    Hope it Helps!!

  • Get Error while update the User defined row table through DSK Code

    Hi experts,
    I have got an error while updating the user row defined table.
    Error is - "Invalid row"
    I have created one master table "@CBF_FARM " and Child table "@CBF_FAR1"
    First i inserted 5 record in the child table so in my my child table there are 5 Line id (1,2,3,4,5 one for each row).
    after that i delete 2 rows (3rd & 4th row) from child table now in my child table there are 3 rows( Line id 1, 2, 5). Please See attachment.
    Now i am updating  the last record of child table through Code  (Line id is 5)  from other form, then i got error  invalid row.
    Following Code used for updating the user defined child table.
      SAPbobsCOM.GeneralService oGeneralService1 = null;
                                    SAPbobsCOM.GeneralData oGeneralData1 = null;
                                    SAPbobsCOM.GeneralDataParams oGeneralParams1 = null;
                                    SAPbobsCOM.CompanyService sCmp1 = null;
                                    SAPbobsCOM.GeneralData oChild1 = null;
                                    SAPbobsCOM.GeneralDataCollection oChildren1 = null;
                                    sCmp1 = clsAddOn.LDNA_Company.GetCompanyService();
                                    oGeneralService1 = sCmp1.GetGeneralService("CBF_FARM");
                                    // Get UDO record
                                    oGeneralParams1 = ((SAPbobsCOM.GeneralDataParams)(oGeneralService1.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));
                                    oGeneralParams1.SetProperty("Code", oForm.Items.Item("edtFarmCd").Specific.Value);
                                    oGeneralData1 = oGeneralService1.GetByParams(oGeneralParams1);
                                    // Add lines on UDO Child Table
                                    oChildren1 = oGeneralData1.Child("CBF_FAR1");
                                    // Create data for rows in the child table
                                    SAPbouiCOM.Item oItem = oForm.Items.Item("cmbShed");
                                    oCombo = oItem.Specific;
                                    string ShedCode = oCombo.Selected.Value;
                                    ldna_Rec = clsAddOn.LDNA_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                                    string strQuery1 = "select LineId from [@CBF_FAR1] where U_ShedCd = " + ShedCode;
                                    ldna_Rec.DoQuery(strQuery1);
                                    oChild1 = oChildren1.Item(ldna_Rec.Fields.Item("LineId").Value - 1);
                                    oChild1.SetProperty("U_Status", "Ready For Schedule");
                                    //Update the UDO Record
                                    oGeneralService1.Update(oGeneralData1);
    Please Help me it is an urgent requirement,
    -Regards
    Vikas

    hi.
    Error is - "Invalid row"
    Now i am updating  the last record of child table through Code  (Line id is 5)  from other form, then i got error  invalid row.
    As per my knowledge
    What i understood is you have 5 lines and you are going to be update 5th line
    am i correct..
    while u are updating the line in child table
    you have to consider like this..
    line number         u have to update like
    1                                        0
    2                                        1
    3                                        2
    4                                        3
    5                                        4
    which means in child table treat
    line 1  as 0
    line 2 as  1
    line 5 as 4
    If you want to update the line 5 u have to mention 4 th line

  • Issue with INSERT INTO, throws primary key violation error even if the target table is empty

    Hi,
    I am running a simple
    INSERT INTO Table 1 (column 1, column 2, ....., column n)
    SELECT column 1, column 2, ....., column n FROM Table 2
    Table 1 and Table 2 have same definition(schema).
    Table 1 is empty and Table 2 has all the data. Column 1 is primary key and there is NO identity column.
    This statement still throws Primary key violation error. Am clueless about this? 
    How can this happen when the target table is totally empty? 
    Chintu

    Nope thats not true
    Either you're not inserting to the right table or in the background some other trigger code is getting fired which is inserting into some table which causes a PK violation. 
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Regarding ORA-00001: unique constraint violation error

    Hi ,
    This is Venkat. I am new to OWB.
    When I run the mapping I am getting the ORA-00001: unique constraint violation error.
    My loading type is Update/Insert.
    My target table Primarykey is combination of 3 keys.
    Please give me the suggestions. It is very urgent.
    Thanks,
    Venkat

    1) If you can disable/drop the indexes on the table, you can load the data and then do a SQL query grouping by the PK/UI to show which rows have a count > 1 i.e. the duplicates.
    2) If you can't alter the target table, perhaps create a dummy copy of the table without pk/indexes and load to that and then do above query.
    3) Run the mapping via the debugger and set a breakpoint just before your target table and examine the data to see if you can spot the duplicates.
    4) Put a deduplicator into the mapping (just before target table), this may allow you to load data but doesn't solve the real problem as to why you have duplicates.
    Si

Maybe you are looking for

  • SQL Server Express 2008 instance fails to start

    I've installed SQL Server Express with a named instance 'SQLSERVER2'. I was able to connect to it and reference it in the management studio. There was a problem though with Visual Studio 9 when running an ASP.NET web application that required connect

  • Posting March 2011 & April 2011 Transactions in parallel

    Hi, During some month-end process in the Legacy System, we could not complete the Transactions for the month of March 2011 in SAP. We have a pressure of opening the New Financial Year (April 2011) on 1st or 2nd of April. Can we open April 2011 withou

  • WT to be made unemployment taxable for FED and states

    A wt is set for not being taxable for unemployment wages. It should be set to be unemployment taxable for FED and all states. Can someone give me a headstart on this plz. Thanks

  • G5 Airport Antenna Alternative

    Hi Guys I have finally managed to install an airport card, but haven't got a very good signal strength, I'm aware there is an apple antenna available, I have seen a few on ebay, but wondered if there was an alternative, i.e buy an antenna which will

  • Limitting the number of records in query

    I like to limit the number of records retrieved in the query. I set Query All Records block property to NO, Query Array Size to the number I want to retrieve. Before doing that, I set form Preference - Array Processing checked. The result is form alw