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

Similar Messages

  • How to find the list of existing tables in a schema using DB link?

    Hi
    I know how to find the list of existing tables in a schema using the following query
    SQL> select * from tab;
    but, how to list the tables using a DB link?
    For Example
    SQL> select * from tab@dblink_name;
    why this doesn't work?
    Pl advice me
    Thanks
    Reddy.

    ORA-02019: connection description for remote database not foundHave you used this database link successfully for some other queries?
    The error posted seems to indicate that the DB Link is not functional at all. Has it worked for any other type of DML operation or is this the first time you ever tried to use the link?

  • How to find out the account group information in customer master record?

    how to find out the account group information in customer master record?
    in which tab? thanks in advance

    Hi
    Go to XD02 and select the Extras from the main menu , you will find Account group info -> click on the No.ranges.
    reward if it helps
    SR

  • How to find child records given a parent key

    I have a master table which is parent for several child tables. I want to display a button to delete a record in master table. I would prefer show this button conditionally so when a master record has child records, I don't show delete button and no error is raised.
    Of course I could scan every child table to find out child records, but I think must exist a generic method
    How can I find out if a given parent key has child records?
    Thanks in advance
    Oscar
    P.S: I'm using 10gR2
    Edited by: user10712087 on 13/01/2009 02:31 PM

    Oscar
    There's no magic/generic way to check that a master row has no associated detail rows. As Pavan says, you have to decide which detail tables to check, and check them using SQL as usual. (Actually, there is a quick way - you delete the row and if there are any child rows with foreign keys that don't cascade, the delete will fail; but of course you can't use this in case the delete succeeds but the user never wants to press the button).
    One addition to Pavan's answer: DO NOT under any circumstances count all the records in every detail table. All you want to know is, is there at least 1 detail record in at least 1 of the tables. No need to count 100 or 1000 rows...
    You can do this like this in your PL/SQL
    FUNCTION check_children(p_master_id IN INTEGER) RETURN BOOLEAN
    IS
      CURSOR c_child1  IS
      select 1 from child_table_1 where master_id = check_children.p_master_id;
      CURSOR c_child2 IS
      select 1 from child_table_2 where master_id = check_children.p_master_id;
      -- etc for all child tables
    l_rec_present integer := null;
    BEGIN
        OPEN c_child_1;
        FETCH c_child_1 INTO l_rec_present;
        CLOSE c_child_1;
        IF l_rec_present i= 1 THEN
            -- there is a child in child_table_1
            RETURN TRUE;
        END IF;
        OPEN c_child_2;
        FETCH c_child_2 INTO l_rec_present;
        CLOSE c_child_2;
        IF l_rec_present i= 1 THEN
            RETURN TRUE;
        END IF;
    -- etc for each child; finally, if no child found:
       RETURN FALSE;
    END;This makes sure that (1) you stop as soon as you find any child, and (2) you don't get any NO_DATA_FOUND or TOO_MANY_ROWS exceptions raised.
    HTH
    Regards Nigel

  • 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

  • How to find the last update date time and user of record field peoplecode

    how to find the last update date time record field peoplecode?
    Thank you.

    One can check the last update date time using the following query
    SELECT LASTUPDDTTM FROM PSPCMPROG WHERE OBJECTVALUE1 LIKE 'RECNAME' AND OBJECTVALUE2 LIKE 'FIELDNAME'

  • How to find child requests?

    Hi DBA's
    Pls tell me how to find the child request of the parent request? from front end and as well as backend...
    Regards,
    SG

    from front end - Login to System Administrator Responsibility
    - View > Requests > Find
    - View > Query by Example > Enter
    - In the Parent field put the request id for the parent request
    - View > Query by Example > Run
    as well as backendNote: 134035.1 - ANALYZEREQ.SQL - Detailed Analysis of One Concurrent Request (Release 11 and up)
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=134035.1

  • How to find time in the existing sap system

    Hello all,
            How to fine time in the existing sap system;where do find the define time in img;plz help me.
    what is the difference between logical system and client?
    plz sugest me
    thanks in advance

    Dear Sameer
    Go to STZAC where you set Time in IMG.
    Thanks
    G. Lakshmipathi

  • UPDATING child table based on the mods to parent record

    I have a one to many relationship between Table A and Table B.
    I have a field in both of my tables that tracks the status of the record in each table. ie: submitted, inprogress, done.
    When records are created in Table A and B, status is set to SUBMITTED. When the application is being reviewed, the status in parent table is changed to INPROGRESS. As soon as the status in Table A changes to INPROGRESS for the parent record, i also want the status in Table B to change to INPROGRESS for the corresponding child records.
    How can I do this? Triggers is one of the solns, but is there something that i can do with the PROCESS option available on the parent form?
    Any help is very much appreciated.

    Hi,
    Firstly, as Oracle is a relational database, you shouldn't need to have the setting on a child record where it will always be the same as the parent record.
    Secondly, a trigger is probably a better place to make the update, if you need to do this, as this would also handle updates outside of Apex.
    Finally, yes you can create a process to do this if you want. You can create an unconditional process (that is, it runs whenever the page is submitted) and does something like:
    UPDATE TABLEB
    SET STATUS = :P1_STATUS
    WHERE FK_ID = :P1_PK_ID
    AND STATUS &lt;&gt; :P1_STATUSAndy

  • How to find the Last logon detail of a deleted user?

    I need to find the last logon detail of a deleted user.I have tried with SM20 i got the details,but i coildnt get for few users.Is there any other way to get this?

    Hi Eva,
    Follow below:-
    1. Go to Se16
    2. table name either USH02 or USH04
    3. provide BNAME row as your user name then execute it
    4. you will get all the entries for that user in the next output screen
    5. Check the Column names like
    MODDA 
    MODTI
    MODBE   
    TCODE REPID
    For the Details which you need.
    The descriptions of this columns are as below:-
    MANDT                        
    Client
    BNAME                        
    User
    MODDA                        
    Modification date
    MODTI                        
    Modification time
    MODBE                        
    Changed by
    TCODE                        
    Not More Closely Defined Area, Pos
    REPID                        
    Program Name
    BCODE                        
    Initial password
    GLTGV                        
    Valid from
    GLTGB                        
    Valid through
    USTYP                        
    User Type
    CLASS                        
    User group
    UFLAG                        
    User Lock Status
    ACCNT                        
    Account number
    PASSCODE                     
    Password Hash Val.(SAH1, 160 Bit)
    CODVN                        
    Password Code Vers.
    PWDINITIAL                   
    Indicator: Password Is Initial
    Let me know if you need further help in this.
    Regards,
    Ram

  • 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

  • To find whether the attachment exists for DIR ( Document Info Record )

    Sir
    We are using DMS to link the Documents pertians to Project .
    Documents are  having the Drawing PDF attachments .
    How to track whether there is attachment exists or Not ?
    ( We have chakced the DRAW & DRAD but no attachment related infomation is observed )
    Pl help
    Regards

    Dear Ashish
    Table                                                                    Description
    DRAD                                                                   Link between document and object
    DRAO                                                                    Originals for documents
    DRAOZ                                                                 Additional files for original for document
    DRAP                                                                     Document log file
    DRAT                                                                     Document descriptions
    DRAW                                                                   Document info record
    DRAZ                                                                     Table for additional files for original
    All the detail store in above mentioned tables...
    so find out your solution with the Help of ABAPer 
    Regards
    Tushar Dave

  • How to find the file is exists or not ?

    Hi,
    I am exporting data from forms to excel file with user intervention. i need to give a message when the user select the existing file.
    How can we find whether the file is exists in the selected path or not in forms?
    Thanks in advance
    gopi

    with webutil you can use the webutil_file.exists function in the webutil pll.

  • EMERGENCY: Need to flashback table, how to find SCN for a time before update happened?

    Hi all,
    I've got a new database 11G, I've not used flashback before, but my retention time is a day...I have a time that the developer did a massive update to a table to corrupt it.
    How do I find the SCN for that time so I can attempt to flashback that table?
    Thank you,
    cayenne

    Thank you..I also found this works:
    SQL> select timestamp_to_scn(to_timestamp('20140103152000','YYYYMMDDHH24MISS')) scn from dual;
           SCN
      98344246
    Well that might NOT work all of the time. But that is just what Oracle does when you give it a timestamp to flashback to: it converts the timestamp to an SCN and then restores data based on that SCN.
    See Flashback Table in the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9012.htm
    TO TIMESTAMP Clause
    Specify a timestamp value corresponding to the point in time to which you want to return the table. The expr must evaluate to a valid timestamp in the past. The table will be flashed back to a time within approximately 3 seconds of the specified timestamp.
    That 'approximately 3 seconds' accuracy is due to that conversion to SCN - Oracle uses its internal table.
    SCN is accurate if you know it but you usually don't.
    Read, and heed, these warnings in the advanced app dev guide
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_flashback.htm
    Guidelines for Oracle Flashback Query
      If a possible 3-second error (maximum) is important to Oracle Flashback Query in your application, use an SCN instead of a timestamp. See General Guidelines for Oracle Flashback Technology.
    General Guidelines for Oracle Flashback Table
      To query past data at a precise time, use an SCN. If you use a timestamp, the actual time queried might be up to 3 seconds earlier than the time you specify. Oracle Database uses SCNs internally and maps them to timestamps at a granularity of 3 seconds.
         For example, suppose that the SCN values 1000 and 1005 are mapped to the timestamps 8:41 AM and 8:46 AM, respectively. A query for a time between      8:41:00 and 8:45:59 AM is mapped to SCN 1000; an Oracle Flashback Query for 8:46 AM is mapped to SCN 1005.
         Due to this time-to-SCN mapping, if you specify a time that is slightly after a DDL operation (such as a table creation) Oracle Database might use an SCN      that is just before the DDL operation, causing error ORA-1466.

  • How does my child use an existing iTunes gift card now that we have family share?

    My son has a balance on iTunes from a gift card, we have added family sharing to our devices and now we can't seem to use his gift card for his purchases. How do I fix this?

    Regarding your statement about the gift card balance being used if redeemed to the organizers account - http://www.apple.com/feedback.
    Regarding redeeming the gift card to the child's account, it is the same as redeeming to yours.  You have to be signed in to the iTunes store using the child's apple ID, then redeem the gift card there.  If you already redeemed the card on your ID, you won't be able to redeem it again.
    Redeem and use iTunes Gift Cards and content codes - Apple Support

Maybe you are looking for

  • Formatting email sent as attachment (FONTS)

    Hi all, We are using BPM 11.1.1.5.0 with FP 4. In our BPM process we have a human task where users enters the data and submit. The control goes to the next human task in the process flow. We are sending human task as attachment with the email notific

  • Error: invalid content type for SOAP: TEXT/HTML; HTTP 400 Bad Request

    Hi Gurus, i am hardly fighting with this error in Communication Channel Monitoring: Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException: java.io.IOException: invalid content type for SOAP: TEXT/HTML;

  • Static after burning a CD

    Lately, I have been having a problem with my iTunes program. I will burn a CD, it will pop out and when I put it into my car stereo (or DVD player) there will be static on it. Also some parts of songs have been like, cut out. More recently, I havn't

  • Qosmio F10 - How to reset the BIOS?

    i have Toshiba Qosmio F10, I forget password. Please help me by reset the BIOS.

  • IWeb and Aperture: any updates since October?

    I've shared the difficulties that others have discussed in getting Aperture, iWeb and iPhoto to play nice together. I use Aperature now because I have so many photos, and I was having to rebuild my iPhoto cache every day (to the tune of 15-30 minutes