Deleting Child Records

I'm a bit confused on how to accomplish the deletion of child records in a master/detail relationship.
I have a master table and a child table. I created a foreign link between the tables. On my detail table, I have a Delete button, which I would like to use for removing child records. I understand for the master table, I will need to enable cascade delete to remove the master and all children records.
Whenever I try to delete a child record I get the following error, integrity constraint - violated child record found. I understand the error, but how can I remove a single child record without deleting the master record. For example, I may have a 1 master record and 20 child records. I only want to remove one of the child records. The deletion seems to work fine when using AppModule or SQL Developer. Thanks.

Thanks Surendrams. Your question made me take another closer look. Apparently, I was calling the Delete operation from the master table. I added another Delete operation in the Bindings from my child table and the deletion is now working. I should have caught this the first time. Thanks.

Similar Messages

  • Delete child record

    hi is there a quikestt way i can delete child record of the parent table,lets say i have 100 record in child record related to one parent how can i delete the 100 record in smart way not by deleting one by one vale

    You coluld find it easily by googling..
    create table test_dept(dept_id number primary key,dep_name varchar2(50));
    create table test_emp(emp_id number primary key,
          dept_id number references test_dept on delete cascade,emp_name varchar2(50));

  • Deleting Child records which are not associated to any parent

    Hi
    We have seen that in the application though the Activty records has been deleted the child records like sample dropped and the roduct details has remained in the system. This happened cos in R18 when contact was deleted activty got deleted but the Activity child records remained in the application.
    we found that child records are present by looking into record utilization.
    Wanted to know if there is any way to delete these child records from teh application cos we are unable to query for them from UI as well as via webservices.
    any pointers would be helpful.
    -MR

    There is not a reporting subject area or folder available on Books. The workaround we employed was to create a field on the entity that was assigned books and that field was checked when the books were assigned. We are using web services to assign books and the web services also updates the field "Books Assigned". This gives us a way of reporting on that field to see those records without book assigned.

  • Create foreign keys to delete child records

    I am unfamiliar with foreign keys, I have 3 tables one is the parent table if a record is deleted in the parent table I would like the record to be deleted from the child record but I think that I am also confused about which should be the parent table
    (purpose is to use in a form)
    parent table (i think)
    AdminEntry table
    entryid ,
    date1,
    date1desc,
    date2,
    date2desc,
    date3,
    date3desc
    In a form each date and its description is placed in the following table
    CalendarEntry table
    calendarid,
    date,
    datedesc
    entryid (fk)?
    so CalendarEntry will have many entries at least 3 from one entryId, this I get but what if I want to delete lets say date2 and date2desc record. If I delete it from AdminEntry table how will calendarEntry table know which one to delete?
    Please help very confused.
    (the other table also inserts to the CalendarEntry table)

    There is a demo of this functionality in Morgan's Library at www.psoug.org under Foreign Keys.
    Look for ON DELETE CASCADE.

  • DELETING child record of same table..  qry  required( complicated)

    hai
    how to delete the child record of same table...?
    Here is the example...
    CREATE TABLE TDA
    (     PKNODAVE VARCHAR2(7 BYTE) NOT NULL ENABLE,
         DTCREATION DATE,
         DAVETRANSFERT VARCHAR2(7 BYTE),
         PKPARC NUMBER(5,0)
    ALTER TABLE TDA ADD CONSTRAINT PK_TDAV8 PRIMARY KEY (PKNODAVE)
    ALTER TABLE TDA ADD CONSTRAINT FK_TDA1 FOREIGN KEY (DAVETRANSFERT)
         REFERENCES TDA (PKNODAVE) ENABLE
    REM INSERTING into TDA
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('1',to_date('05-JAN-10','DD-MON-RR'),'1',10);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('2',to_date('05-JAN-10','DD-MON-RR'),'2',10);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('3',to_date('05-JAN-10','DD-MON-RR'),'3',10);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('4',to_date('05-JAN-10','DD-MON-RR'),null,10);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('5',to_date('05-JAN-10','DD-MON-RR'),'4',14);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('6',to_date('05-JAN-10','DD-MON-RR'),'5',15);
    DELETE FROM TDA WHERE davetransfert IN ( SELECT PKNODAVE FROM TDA WHERE PKPARC='10')
    ERROR: FK_TDA1 CHILD RECORD FOUND...
    Pls give me the suggestions to solve this
    S

    You could try with a recursive procedure like this
    Processing ...
    select *
    from TDA
    Query finished, retrieving results...
    PKNODAVE      DTCREATION    DAVETRANSFERT   PKPARC  
    1                   05/01/10 1                     10
    2                   05/01/10 2                     10
    3                   05/01/10 3                     10
    4                   05/01/10                       10
    5                   05/01/10 4                     14
    6                   05/01/10 5                     15
    6 row(s) retrieved
    Processing ...
    declare
         cursor c is
              SELECT PKNODAVE FROM TDA WHERE PKPARC='10';
         procedure tda_cascade_delete(
                   del_PKNODAVE in varchar2
         as
              cursor sons is
                   select PKNODAVE
                   from TDA
                   where DAVETRANSFERT = del_PKNODAVE
                        and PKNODAVE <> DAVETRANSFERT;
         begin
              for x in sons loop
                   tda_cascade_delete(x.PKNODAVE);
              end loop;
              delete TDA
              where PKNODAVE = del_PKNODAVE;
         end;
    begin
         for x in c loop
              tda_cascade_delete(x.PKNODAVE);
         end loop;
    end;
    Processing ...
    select *
    from TDA
    Query finished, retrieving results...
    PKNODAVE      DTCREATION    DAVETRANSFERT   PKPARC  
    0 row(s) retrievedPS. A connect by subquery of the type
    delete tab
    where pk in (
              select fk
              from tab
              start with <my condition>
                   connect by fk = prior pk
         ) or <my condition>l;wouldn't generally work because it could try to delete a record before its children.
    Bye Alessandro

  • Problem in deleting child record

    Hi,
    I have a requirement to remove the child records.
    I have two database tables (without any foreign key or database constraints). I have created EOs (ParentEO and ChildEO) and Association. I have created view objects (ParentVO with a transient attribute called "SelectFlag" and ChildVO) based on EOs.
    I have created a MollyViewLink and created Application module (MollyAM) .VOs are associated with AM.
    For detail records, I have created delete icon and I have written below code to handle the deleteChild event in detail region's controller:
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    if ("deleteChild".equals(pageContext.getParameter(EVENT_PARAM)))
    MollyAMImpl am = (MollyAMImpl)pageContext.getApplicationModule(webBean);
    String rowReference = pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    System.out.println("Child ROW Reference =="+rowReference);
    MollyUserDetailsVORowImpl voRow = (MollyUserDetailsVORowImpl)am.findRowByRef(rowReference);
    String parentID = voRow.getId().toString();
    System.out.println("ID is : "+ parentID);
    voRow.remove();
    System.out.println("Child row deleted successfully...");
    am.getTransaction().commit();
    When I click on delete icon at child record, I get below SOP messages:
    Child ROW Reference ==MollyAM.MollyUserDetailsVO_MollyViewLink_MollyUserDetailsVO:MollyUserDetailsVO_MollyViewLink_MollyUserDetailsVO_0{null}
    ID is : 52
    Child row deleted successfully...
    Child record is also being removed from UI. But when I query the database, I can still see the records there. For me, it seems like commit is not affecting the child table.
    Similar code to delete the parent record is working fine.
    Thanks!!!

    Hi Vinod ,
    I am deleting condition record number if  know any function module  please let me know
    problem happing in PRD for particular condition numer it showing INTERNAL ERROR (This is the condition table A923)
    that condition number is their in KONH but not their in KONP because of that  INTERNAL ERROR occuring
    for that i have writen code for that deleting the condition number  ....
    if know any thing please let me know

  • Does not delete child records - ADF-BC

    I am using ADF-BC to display data from three tables.
    I have a main view and a two view links to the children. when I try to delete the master record it says - Integrity constraint violated - child record found. And one more thing even though it does not delete the child records it deletes the master record from the view (only form the view, not from the database).
    How can I make it delete the child record first.
    Thanks

    I did the while exercise one more time and it started working. thanks.
    Now I have another problem. I have to keep that commit button on the page. If I delete the comit button from the page it gives me nullpointer exception at the line
    operationBinding = bindings.getOperationBinding("Commit");
    How can I solve this
    Thanks

  • 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

  • To delete child records manually without using oracle's delete cascade

    Hi all
    I have to write a procedure that accepts schema name, table name and column value as parameters....I knew that i need to use metadata to do that deleting manually....I am a beginner...can somebody help me with the procedure?

    Hi Guru,
    They told me to use this procedure...but this procedure isn't working...can you help me to understand this procedure?
    CREATEOR REPLACE PROCEDURE delete_cascade(
        table_owner          VARCHAR2,
        parent_table         VARCHAR2,
        where_clause         VARCHAR2
    )IS
        /*   Example call:  execute delete_cascade('MY_SCHEMA', 'MY_MASTER', 'where ID=1'); */
        child_cons     VARCHAR2(30);
        parent_cons    VARCHAR2(30);
        child_table    VARCHAR2(30);
        child_cols     VARCHAR(500);
        parent_cols    VARCHAR(500);
        delete_command VARCHAR(10000);
        new_where_clause VARCHAR2(10000);
        /* gets the foreign key constraints on other tables which depend on columns in parent_table */
        CURSOR cons_cursor IS
            SELECT owner, constraint_name, r_constraint_name, table_name, delete_rule
              FROM all_constraints
             WHERE constraint_type ='R'
               AND delete_rule ='NO ACTION'
               AND r_constraint_name IN(SELECT constraint_name
                                           FROM all_constraints
                                          WHERE constraint_type IN('P','U')
                                            AND table_name = parent_table
                                            AND owner = table_owner)
               ANDNOT table_name = parent_table;-- ignore self-referencing constraints
        /* for the current constraint, gets the child columns and corresponding parent columns */
        CURSOR columns_cursor IS
            SELECT cc1.column_name AS child_col, cc2.column_name AS parent_col
              FROM all_cons_columns cc1, all_cons_columns cc2
             WHERE cc1.constraint_name = child_cons
               AND cc1.table_name = child_table
               AND cc2.constraint_name = parent_cons
               AND cc1.position = cc2.position
            ORDERBY cc1.position;
    BEGIN
        /* loops through all the constraints which refer back to parent_table */
        FOR cons IN cons_cursor LOOP
            child_cons   := cons.constraint_name;
            parent_cons  := cons.r_constraint_name;
            child_table  := cons.table_name;
            child_cols   :='';
            parent_cols  :='';
            /* loops through the child/parent column pairs, building the column lists of the DELETE statement */
            FOR cols IN columns_cursor LOOP
                IF child_cols ISNULLTHEN
                    child_cols  := cols.child_col;
                ELSE
                    child_cols  := child_cols ||', '|| cols.child_col;
                ENDIF;
                IF parent_cols ISNULLTHEN
                    parent_cols  := cols.parent_col;
                ELSE
                    parent_cols  := parent_cols ||', '|| cols.parent_col;
                ENDIF;
            END LOOP;
            /* construct the WHERE clause of the delete statement, including a subquery to get the related parent rows */
            new_where_clause  :=
                'where ('|| child_cols ||') in (select '|| parent_cols ||' from '|| table_owner ||'.'|| parent_table ||
                ' '|| where_clause ||')';
            delete_cascade(cons.owner, child_table, new_where_clause);
        END LOOP;
        /* construct the delete statement for the current table */
        delete_command  :='delete from '|| table_owner ||'.'|| parent_table ||' '|| where_clause;
        -- this just prints the delete command
        DBMS_OUTPUT.put_line(delete_command ||';');
            EXECUTE IMMEDIATE delete_command;
        -- remember to issue a COMMIT (not included here, for safety)
    END;Edited by: BluShadow on 09-Oct-2012 16:05
    added {noformat}{noformat} tags for readability.  Please read: {message:id=9360002} and learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Removing child records

    Hi,
    I am using below code to delete the child records for a particular parent record in the Controller:
    But the problem is, it is going in the loop and says deleting records...but data is still present in detail table.
    Please help!
    if ("delete".equals(pageContext.getParameter(EVENT_PARAM)))
    MollyAMImpl am = (MollyAMImpl)pageContext.getApplicationModule(webBean);
    MollyUserDetailsVOImpl voChild = am.getMollyUserDetailsVO1();
    String rowReference = pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    System.out.println("ROW Reference =="+rowReference);
    MollyUsersVORowImpl voRow = (MollyUsersVORowImpl)am.findRowByRef(rowReference);
    String parentID = "" + voRow.getId();
    System.out.println("The Id value to be removed from child table is "+ parentID);
    voChild.setWhereClause("");
    voChild.setWhereClause("ID =" + parentID);
    System.out.println("Child VO Query to execute : "+voChild.getQuery());
    voChild.executeQuery();
    System.out.println("Remove - Child Query was sucessfull");
    int childRecords = voChild.getRowCount();
    System.out.println("Remove - child records to delete: "+ childRecords);
    Row childRow=voChild.first();
    for(int i=1;i<=childRecords;i++)
    childRow.remove();
    System.out.println("Deleting child record "+ i);
    childRow=voChild.next();
    am.getTransaction().commit();
    System.out.println("committed.....");
    System.out.println("All child deleted successfully");
    }

    Hi Gyan,
    Thanks for the reply. Please find below SOP values. I have checked the Query, Ids is correct there...
    ROW Reference ==MollyAM.MollyUsersVO1:MollyUsersVO1{74}
    The Id value to be removed from child table is 74
    Child VO Query to execute : SELECT MollyUserDetailsEO.ID, MollyUserDetailsEO.PKG_NAME, MollyUserDetailsEO.PKG_CASE, MollyUserDetailsEO.CREATION_DATE, MollyUserDetailsEO.CREATED_BY, MollyUserDetailsEO.LAST_UPDATE_DATE, MollyUserDetailsEO.LAST_UPDATE_LOGIN, MollyUserDetailsEO.LAST_UPDATED_BY, MollyUserDetailsEO.DETAIL_ID FROM XXE_FXX_USER_DETAILS MollyUserDetailsEO WHERE (ID =74)
    Remove - Child Query was sucessfull
    Remove - child records to delete: 5
    Deleting child record 1
    Deleting child record 2
    Deleting child record 3
    Deleting child record 4
    Deleting child record 5
    committed.....
    All child deleted successfully

  • APP-PAY-07201 Cannot perform a delete when child record exists in future

    I am trying to put end date to a payment method of any employee in HR/Payroll 11.5.10.2
    but receiving the following error message:
    APP-PAY-07201 Cannot perform a delete when child record exists in future
    Can u advise what steps I should follow to resolve this issue.
    Regards /Ali

    This note is related to termination of employee while our employee is on payroll and just want to change is payment method. But in the presence of existing payment method we cannot attched another becuase we are receiving an error:
    APP-PAY-07041: Priority must be unique within an orgainzational payment method

  • How to delete the child record from the database

    how to delete a parent and child record from the database can we do it in the servlet and my database is oracle

    I'm not sure I understand the question but you could certainly use the JDBC API from within your servlet to access and modify a DB. You could also use an EJB layer to access your DB and accomplish the same tasks.

  • Facing problem while deleting a child record in hibernate.

    I am trying to update a child records i have following scenario
    master record (having one to many assciation with child table cascade=all in .hbm.xml configuration file) ===> customerInfo
    detail record set (having many to one assciation with master table cascade=all in .hbm.xml configuration file) ===> customerAccountsSet
    i do following steps to update a record
    1) get the customerInfo objetc from session successfully
    2) get the customerAccountsSet = customerInfo.getCustomerAccounts();
    3) traying to add a new customerAccount say customerAccount1 to be saved for the first time without primery key in it
    4) traying to update a customerAccount say customerAccount2 to be updated with primery key in it
    5) traying to add a delete customerAccount say customerAccount3 with primery key in it
    only step 5 is not executed properly as i can still see the deleted record in db , although save and update steps have been successfully completed in db.
    can anybody tell me whats going wrong here.code for steps 2,3,4,5 is as follows in the same order
    2)Set customerAccountSet = (Set) customerInfo.getCustomerAccounts();
    3)customerAccountSet.add(customerAccount);
    4)customerAccountSet.add(customerAccount);
    5)customerAccountSet.remove(customerAccount);

    Hi Nitesh,
    1) Java stack should be up while trying to connect to R/3 backend.
    2) You can check the JCOs by doing the following:
                           Type the following url   http://<server name>:<port number>
                           Click on Webdynpro Console
                           Enter the user name and password.(You need the system admin right on the EP to do the same)
                           You can find the JCOs.
    3) Better you contact the basis guy who had created the JCOs earlier and get the JCOs tested.
    Hope it helps.
    Regards.
    Rajat
    Edited by: Rajat Jain on Oct 12, 2009 1:47 PM

  • How to delete a Record in  Masterdata  and its Child Tables

    Hi ,
    i want to delete a  record in masterdata and its childtable .
    I am using generalservices.But it  gets error "Attempt to read or write protected memory"
    If there is another solution to delete records in all child tables.
    Edited by: tharunireddy on Aug 13, 2010 3:08 PM

    Hi,
    There must be something wrong with your code.
    Please post it here so we can determine the problem and present a solution.
    Regards,
    Vítor Vieira

  • 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

Maybe you are looking for