Can't Delete Parent Record - On Delete Cascade is set

Greetings all,
I have a parent and child table and when I attempt to delete the parent record, I get the following error:
ORA-02292: integrity constraint (WFSTEADMAN.INCIDENT_NOTES_TBL_FK) violated - child record found
     Error      Unable to process row of table MYTEST_INCIDENTS.
I have the the FK set to ON DELETE CASCADE so I am not sure what the issue might be.
Below are the structures of my parent and child tables:
I am using apex.oracle.com so the version is: Application Express 4.0.2.00.06
Any assistance would be appreciated.
Wally
PARENT TABLE:
=============================================================
CREATE TABLE "MYTEST_INCIDENTS"
(     "INCIDENTID" NUMBER NOT NULL ENABLE,
     "INCIDENTCREATED" DATE NOT NULL ENABLE,
     "INCIDENT_OWNER" VARCHAR2(200) NOT NULL ENABLE,
     "DTGSTART" DATE NOT NULL ENABLE,
     "DTGEND" DATE,
     "INCIDENT_SERVICES" VARCHAR2(4000),
     "INCIDENT_CUSTOMERS" VARCHAR2(4000),
     "INCIDENT_DESCRIPTION" VARCHAR2(4000),
     "INCIDENT_TIMELINE" VARCHAR2(4000),
     "INCIDENT_TRACKING" VARCHAR2(500),
     "INCIDENT_RESTORE" VARCHAR2(4000),
     "INCIDENT_FOLLOWUP" VARCHAR2(4000),
     "INCIDENT_LEVEL" NUMBER,
     "INCIDENT_TITLE" VARCHAR2(500),
     "EMAIL_NOTIFY" VARCHAR2(4000),
     "TEXT_NOTIFY" VARCHAR2(4000),
     "LEVEL_TYPE" VARCHAR2(25),
     CONSTRAINT "MYTEST_INCIDENTS_PK" PRIMARY KEY ("INCIDENTID") ENABLE
CREATE OR REPLACE TRIGGER "BI_MYTEST_INCIDENTS"
before insert on "MYTEST_INCIDENTS"
for each row
begin
if :NEW."INCIDENTID" is null then
select "MYTEST_INCIDENTS_SEQ".nextval into :NEW."INCIDENTID" from dual;
end if;
end;
ALTER TRIGGER "BI_MYTEST_INCIDENTS" ENABLE;
CHILD TABLE
=============================================================
CREATE TABLE "MYTEST_INC_NOTES"
(     "NOTEID" NUMBER NOT NULL ENABLE,
     "INCIDENT_ID" NUMBER NOT NULL ENABLE,
     "NOTE_DTG" DATE,
     "NOTE_OWNER" VARCHAR2(200),
     "NOTE_COMMENTS" VARCHAR2(4000),
     CONSTRAINT "MYTEST_INC_NOTES_PK" PRIMARY KEY ("NOTEID") ENABLE
) ;ALTER TABLE "MYTEST_INC_NOTES" ADD CONSTRAINT "MYTEST_INC_NOTES_CON" FOREIGN KEY ("INCIDENT_ID")
     REFERENCES "MYTEST_INCIDENTS" ("INCIDENTID") ON DELETE CASCADE ENABLE;
CREATE OR REPLACE TRIGGER "BI_MYTEST_INC_NOTES"
before insert on "MYTEST_INC_NOTES"
for each row
begin
if :NEW."NOTEID" is null then
select "MYTEST_INC_NOTES_SEQ".nextval into :NEW."NOTEID" from dual;
end if;
end;
ALTER TRIGGER "BI_MYTEST_INC_NOTES" ENABLE;
CREATE OR REPLACE TRIGGER "MYTEST_INC_NOTES_T1"
BEFORE
insert or update on "MYTEST_INC_NOTES" REFERENCING NEW AS NEW OLD AS OLD
for each row
begin
:NEW.NOTE_DTG := SYSDATE;
end;
ALTER TRIGGER "MYTEST_INC_NOTES_T1" ENABLE;

Yeah there was a rampant child table still left out there. Noticed the issue and deleted the child and all is well now. :). Should have looked for a couple more minutes before posting.
Thanks
Wally

Similar Messages

  • How to find child records is exists before to delete parent records.

    Dear Everyone,
    I would like to ask you, is there any simple way to find child records is exists before to delete parent records.
    I have a master table defined primary key and I have referenced that as foreign key in many tables.
    I have used Delete_Record to delete but it isn't display the message 'child record exist' but it cleared the record from the form. So I need to know how to find child records is exists or not before to do delete_record so that I can display message in-case it exists.
    I do know we can able to check in every table matching the column manually, but what if we use 100 of tables then it is not possible to check manually.
    I am sure there must be simple way to find as how the oracle identifies when we execute delete query.
    Please help me on this.
    Thanks in advance.

    Simple solution is to run the query I have given for all child tables or to try a single query for all child tables withj something like:
    select <parent_key>
    from <parent_table>
    where <parent_key> in
              (select <foreign_key_1> from <child_table_1> union
               select <foreign_key_2> from <child_table_2> union
               ... );More complicate solution could be to change the foreign key constraints to cascade DELETE on parent table to child tables:
    SQL>
    SQL> create table p(x int primary key);
    Table created.
    SQL> create table c1(x1 int);
    Table created.
    SQL> create table c2(x2 int);
    Table created.
    SQL>
    SQL> alter table c1 add constraint fk1 foreign key(x1) references p;
    Table altered.
    SQL> alter table c2 add constraint fk2 foreign key (x2) references p;
    Table altered.
    SQL>
    SQL>
    SQL> insert into p values(1);
    1 row created.
    SQL> insert into c1 values(1);
    1 row created.
    SQL> insert into c2 values(1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL>
    SQL> alter table c1 drop constraint fk1;
    Table altered.
    SQL> alter table c2 drop constraint fk2;
    Table altered.
    SQL>
    SQL> alter table c1 add constraint fk1 foreign key(x1) references p on delete cascade;
    Table altered.
    SQL> alter table c2 add constraint fk2 foreign key (x2) references p on delete cascade;
    Table altered.
    SQL>
    SQL> delete p where x=1;
    1 row deleted.
    SQL> commit;
    Commit complete.
    SQL> select * from p;
    no rows selected
    SQL> select * from c1;
    no rows selected
    SQL> select * from c2;
    no rows selected
    SQL>Edited by: P. Forstmann on 27 oct. 2011 14:01

  • Iphone4 to 6.3.1, not single delete personal records Even deleted

    Why update my iphone4 to 6.3.1, not single delete personal records
    Even deleted, not when the machine is flash back
    I delete the phone number will appear simply no way to single delete records of calls reopen

    Please post in your native language. This makes very little sense in English.

  • ADF,how to delete parent record and related child record without manual cod

    Hi All,
    I'm using 11g adf.
    I have one parent table PAR and two child table CHD1 , CHD2 respectively.
    I'm inserting values in three tables , making a form having add , delete and edit buttons.
    Issue when i want to delete a record from PAR table , it gives child table record exists . i have did manual coding to delete the child records with related to the selected parent table PAR.
    Is there any process in ADF to delete the child records with respective selected parent record with out manual coding.
    thanks in advance.

    http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcentities.htm#BABHFJFJ
    John

  • Delete master record without deleting corresponding details

    Hi all,
    If we have a master-detail relation and we delete the master record, the “Implement cascade delete” flag can be selected to delete the detail records also.
    Now, what if I don’t want to delete the detail records, but instead set the corresponding attribute (that points to the master) in this record to null.
    For ex when deleting a department record, I need to set the “dpartmentId” field of all the corresponding employee records to null instead of deleting these records.
    Is there a configuration that can be made to tell ADF automatically do this?
    Thank you.

    No, adf doesn't have such a mechanism. You can program it yourself by unsetting the cascade delete flag and before removing the master iterate over the child records and set the fk value to null.
    Our you do this in the db using a trigger.  In this case you have to refresh the child vo too.
    Timo

  • I want to delete parent record so that its child is automatically deleted

    Hi Gurus , i was trying to delete the child record as soon as parent is deleted.
    How do we do that?
    I can delete child 1st but it seems that there are lots of child data in different table.
    I have heard 'on delete cascade ' does that.
    Can you please help me out how to use that in delete statement???

    You should change your relationship to on delete = cascade. For example:
    alter table tb2 drop constraint fk;
    alter table tb2 add constraint fk foreign key (n) references tb1(n) on delete cascade;
    When you delete father table, will be deleted all children that have relationship like delete cascade.

  • Deleting parent record with child instances

    Is there a way i can delete records from the database when i have one of the columns being used in other tables.
    Eg: m_id used in tables meter ( Primary key ) and period_meter( foreign key) and site_area_meter (foreign key). I want to delete record whose m_id is so and so...
    if not then any other idea to discard that parent , child records
    thanks in advance

    I was able to solve my problem by using the item tag to the Navigate Tree: Get Parent invoke node and then wiring through the item to the next item tag as needed.
    I attached a screen shot.
    Kenny
    Kenny
    Attachments:
    get items from tree control.gif ‏4 KB

  • Deletion of Parent Record

    Hi!
    I want to delete parent record, but error comes that Child record present.
    Is any way to delete Parent Record.
    Regards!

    Maybe you might want to do away with the Foreign Key constraint altogether? What is the purpose of having a parent-child relationship if the child row can exist without any changes even if the parent row is deleted? The closest option available with ON DELETE is SET NULL, where the child rows will be set to NULL if the parent row is deleted, however I don't think this is what you are trying to achieve. If you want a child row to exist even if the parent is deleted, either disable or drop the constraint, for it makes no real sense to have it anyway.

  • Getting Problem after Deleting a record from Record Store

    I am trying to create a simple application for mobile device. This application storing some records. I used RMS for this. These records i show in a list. But i tried to show list of records after deleting any record then list shows only prior records of deleted records n then shows exception as
    Recordsjavax.microedition.rms.InvalidRecordIDException
    The code i written as follows
    For storing data
    public void storeExercise(String EName, String Etime)
    try
    //System.out.println("AAAA");
    recordstore = RecordStore.openRecordStore("Test3",true);
    catch (Exception error)
    //System.out.println("EEEE");
    System.out.println("Exception"+error);
    try
    byte[] outputRecord;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DataOutputStream outputdataStream = new DataOutputStream(outputStream);
    outputdataStream.writeUTF(EName);
    outputdataStream.writeUTF(Etime);
    outputdataStream.flush();
    outputRecord = outputStream.toByteArray();
    recordstore.addRecord(outputRecord, 0, outputRecord.length);
    outputStream.reset();
    outputStream.close();
    outputdataStream.close();
    zlist.append(EName+Etime, null);
    display.setCurrent(zlist);
    catch (Exception error)
    System.out.println("Exception in writing Records"+error);
    for getting records
    public void getExercise(ZimList zlist)
    this.zlist = zlist;
    try
    //System.out.println("AAAA");
    recordstore = RecordStore.openRecordStore("Test3",true);
    //recordstore.closeRecordStore();
    catch (Exception error)
    //System.out.println("EEEE");
    System.out.println("Exception"+error);
    try
    //System.out.println("Hello");
    String Ename = null;
    String Etime = null;
    byte[] byteInputData = new byte[100];
    ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
    DataInputStream inputDataStream = new DataInputStream(inputStream);
    for (int x=1; x<= recordstore.getNumRecords() ; x++ )
    System.out.println("Record Id ="+x);
    //if (x != InvalidRecordID)
    recordstore.getRecord(x, byteInputData, 0);
    Ename = inputDataStream.readUTF();
    Etime = inputDataStream.readUTF();
    inputStream.reset();
    Final = Ename + Etime;
    System.out.println("Insert" + Final);
    zlist.insert(x-1,Final,null);
    inputStream.close();
    inputDataStream.close();
    //recordstore.closeRecordStore();
    catch (Exception error)
    System.out.println("Exception in Reading Records"+error);
    /*if (recordstore.listRecordStores() != null)
    try
    recordstore.deleteRecordStore("My Record Store");
    catch (Exception error)
    System.out.println("Exception"+error);
    And for deleting records I write
    public void deleteExercise(int index)
    try
    //System.out.println("AAAA");
    recordstore = RecordStore.openRecordStore("Test3",true);
    //recordstore.closeRecordStore();
    catch (Exception error)
    //System.out.println("EEEE");
    System.out.println("Exception"+error);
    if (recordstore.listRecordStores() != null)
    try
    byte[] byteInputData = new byte[100];
    ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
    DataInputStream inputDataStream = new DataInputStream(inputStream);
    for (int x=1; x<= recordstore.getNumRecords() ; x++ )
    recordstore.getRecord(x, byteInputData, 0);
    if (x == index)
    recordstore.deleteRecord(index);
    //x--;
    inputStream.reset();
    break;
    inputStream.close();
    inputDataStream.close();
    catch (Exception error)
    System.out.println("Exception in Deleting Records"+error);
    Please Help me bcz i am new in j2me development n having no experience

    Ok ...
    When you add records in you store, the J2ME implementation create an ID.
    In the database, there is a list like that with ID <--> ]byte[ ]
    You can get back a record with a this ID.
    When you delete a record, it deletes the row. Lets say you have stored 3 records and that the ID are 1, 2, 3 ... if you delete the second one, then you have still in the database IDs 1 and 3.
    That's why you have this exception : you are iterating with an ID 1, 2, 3, 4, 5 ... if one is delete there is no reorganization. (If you add an other record, it could be stored with ID 2).
    To read all the records, you should get a list of existing IDs. Take a look at the API. Here is a piece of code, that you work but I have not tested :
    RecordStore rs;
    RecordEnumeration re = rs.enumerateRecords(null, null, false);
    while (re.hasNextElement()) {
      String str = new String(re.nextRecord());
      System.out.println("Record: " + str);         
    } Hope it will help you.
    Regards

  • SM30 - Deleting a record with Foriegn Key Constraints

    I have a two custom tables ZCCED_STATUS and ZCCED_COSTITEM. 
    ZCCED_COSTITEM has a status column with a foriegn key to a (PK) status record in ZCCED_STATUS.
    I have generated table maintenance objects for the table ZCCED_STATUS.
    When I go to SM30 and maintain the table ZCCED_STATUS I can select a status record and delete it. (still ZCCED_COSTITEM records using that status)
    Is there any way that SM30 can warn or stop a user from deleting a ZCCED_STATUS record when there are child records in the ZCCED_COSTITEM table?
    Regards,

    Create a maintenance view , link both tables and generate a table maintenance for the maintenance view . it will work.

  • "Hiding" records with delete status

    Hi,
    In my project we use logical deletion from the DB, meaning that records have an is_deleted column.
    Whenever I want to logically delete a record I just need to set the is_deleted field to 1.
    The problem is as follows:
    I have two objects A,B and to tables T_A and T_B that relates to these objects respectively.
    Both objects have is_deleted field, and A contains a list of B objects.
    When getting from A the list of Bs it returns also the ones with is_deleted=1.
    What is your recommendation to solve this problem?
    Is there a way of telling toplink not to load these records at all?
    Thanks,
    Lior.

    You can either filter the deleted objects for the specific mapping or for all queries for the class.
    To filter all queries for a class you can use a descriptor additionalJoinExpression. This is an expression that can be set in a descriptor's query manager, this feature is only available through the code API, so you need to use a descriptor amendment method to define it from the Mapping Workbench.
    Example:
    ExpressionBuilder builder = new ExpressionBuilder();
    descriptor.getQueryManager().setAdditionalJoinExpression(
    builder.getField("A.IS_DELETED").equal(1));
    This will cause all queries for the A class to filter out deleted objects.
    If you only wanted the filter on the A->B relationship mapping you could use a mapping selectionCriteria that filters on the is_deleted flag. Refer to the follow thread for an example of a mapping selectionCriteria filter.
    Filtering results on the child vector

  • Update new records and delete old record? Urgent

    Iam updating some records from internal table to Data base table.
    Please suggest me
    INSERT DBTable FROM TABLE itab.     
    UPDATE DBTable FROM  itab.
    Delete existing records.
      DELETE  DBTable FROM TABLE itab_old.
    Please suggest me

    Got you..
    Iam colecting some records to internal table from Data base table
    based on year and month.
    Then changing the date and months in interenla table
    then inserrting this modified records of internal table into datta base table.
    Finaly delete the old records with old dates.
    Here is the suggestion..This is a logic and not the exact code..
    DATA: ITAB TYPE STANDARD TABLE OF ZTABLE WITH HEADER LINE.
    DATA: ITAB_OLD TYPE STANDARD TABLE OF ZTABLE WITH HEADER LINE.
    SELECT * FROM ZTABLE
           INTO TABLE ITAB.
    ITAB_OLD = ITAB.
    ITAB-NEW_DATE = SY-DATUM.
    MODIFY ITAB TRANPORTING NEW_DATE WHERE KEY_FIELD = 'DS'.
    Deletion part.
    DELETE ZTABLE FROM TABLE ITAB_OLD.
    Insertion part
    INSERT ZTABLE FROM TABLE ITAB.
    Thanks,
    Naren

  • Delete Duplicate Record leaving  1 record

    Hi friends
    I want to delete a record from table where there is duplicate which i am able to do it , but i want while deleting it should leave 1 record.
    for ex
    1111
    1111
    2222
    2222
    it should delete all duplicate and leave the unique one.
    1111
    2222
    sandy

    Here are some ideas:
    AskTom: Deleting duplicate records
    AskTom: Deleting duplicate records without using rowid and rownum
    AskTom: to remove duplicate records

  • Delete child records before I can delete the parent

    Hello,I'm a newbie to SQL and if it is not to difficult I can succeed to write querie's. I don't much know about PL/SQL.
    We are working with Oracle.The parent ERD is this.
    Table 1 --> linking Table --> Table 2 --> Table 3(detail)
    1 | 1 1 1 1 1 n
    |--> Table 1 detail
    1
    Now I want to delete for every record of table 1 who doesn't have a record in the table 1 detail.
    But before I can do this:
    - I have to delete the one or more records in table 3,
    - then in table 2 and then the records in the linking table
    - and at last the records from Table 1, which is the parent.
    Can anybody help or put me in a direction how to solve this?
    Cascade doesn't work I think.
    I mean by 'Linking table' a table with only three UID's(Table 1, Table 3 and his self)
    I mean by the numbers the relation between the tables.
    I'm working with Toad
    Thanks in advance,
    Nico

    if I am understanding you correctly you have 3 tables kind of like this
    create table  table1 as (select 1 t1_id from dual union
                          select 2 from dual union
                          select 3 from dual);
    create table      table2 as (select 1 t2_id, 1 t1_id from dual union
                          select 2 t2_id, 1 t1_id from dual union
                          select 3 t2_id, 2 t1_id from dual union
                          select 3 t2_id, 2 t1_id from dual);
    create table  table3  as (select 1 t3_id, 1 t2_id from dual union
                          select 2 t3_id, 1 t2_id from dual union
                          select 3 t3_id, 2 t2_id from dual);
    select t1_id, t2_id, t3_id
    from  table1 left outer join table2 using (t1_id) left outer join table3 using (t2_id)
    order by t1_id;
    T1_ID     T2_ID     T3_ID
    1     1     1
    1     1     2
    1     2     3
    2     3     
    3          so you would like to delete table 1 t1_id 2 and 3 because there are no corresponding entris in table 3 (the detail table)
    delete from table1 where t1_id in
      select t1_id
    from  table1 left outer join table2 using (t1_id) left outer join table3 using (t2_id)
    where t3_id is null
    select * from table1;
    t1_id
    1of course that leaves you with orphans so you will need to clean up table 2
    delete from table2 where  t1_id not in
    (select t1_id from table1);why won't a cascade delete work?
    Edited by: pollywog on Nov 18, 2010 12:03 PM

  • How to delete parent table data even though it has child records

    hi all,
    How to delete parent table data even though it has child records.
    ex: delete from pa_request cascade constraints;
    But this command is not working .
    Regards,
    P Prakash

    833560 wrote:
    ex: delete from pa_request cascade constraints;cascade constraints is DROP table option. It can't be used with DELETE. You need to delete child rows first or drop foreign keys and recreate them with ON DELETE CASCADE. Then:
    delete from pa_request will automatically delete child rows. However, personally I don't like ON DELETE CASCADE. You can, by mistake, delete half of your database without even realizing it.
    SY.

Maybe you are looking for

  • Unable to start ORACLE 8.1.5 on RedHat 6.2

    completed installation of Oracle 8.1.5 on Redhat 6.2. dbassist reports that it had created a database for me. But I am unable to "STARTUP" the oracle instance successfully. I get "Load Indicator not supported by OS" message in the "alert" log. null

  • Backing up Data in Apex

    Hello, Please does anyone knows how I could back up vital data in my application. How can I set up back up process whenever a user wants to close/log out from the application. Is it possible in Apex Thanks

  • JTable in AWT  ?

    Hi Friends In Swings we have JTable to Construct a Table. Is there anything like that in AWT ?? Thanksinadvance Yours Rajesh

  • Excel table to update spry data set (?)

    Hello again! In my last posted I asked for a scrolling text script.. I have decided to use spry data set to update shipping info - the problem I am not running into is - I need my corker(s) to be able to update this too - I of course understand rows

  • BizTalk mapper - sum over a group

    I'm working on EDI 820, need to create a map for integration to our ERP. If we have two payments against one invoice, I need to combine them, basically, group the amounts by invoice. So at the input I'd have: <ns0:ENTLoop1> <ns0:RMRLoop1> - <ns0:RMR>