Help needed writing trigger for deleting records from multipul tables

i am trying to write a trigger which would help me delete the record from 3 different tables
lets say i have table a , b and c
i an trying to write a trigger which would help me delete the same record from table a and c.
drop trigger az_zzz_trigger;
create trigger az_zzz_trigger
before INSERT or UPDATE or DELETE ON az_employ
FOR EACH ROW
BEGIN
IF DELETING then
delete from za_payroll
delete from az_salary_audit
end if;
end;
while executing this trigger all data of table za_payroll is delete.
what should i do so that only the record which i delete from az_employ gets deleted from az_payroll and az_salary_audit

872959 wrote:
i am trying to write a trigger which would help me delete the record from 3 different tables
lets say i have table a , b and c
i an trying to write a trigger which would help me delete the same record from table a and c.
drop trigger az_zzz_trigger;
create trigger az_zzz_trigger
before INSERT or UPDATE or DELETE ON az_employ
FOR EACH ROW
BEGIN
IF DELETING then
delete from za_payroll
delete from az_salary_audit
end if;
end;
while executing this trigger all data of table za_payroll is delete.
what should i do so that only the record which i delete from az_employ gets deleted from az_payroll and az_salary_auditutilize appropriate WHERE clause

Similar Messages

  • Delete records from multiple table

    Hi,
    I need to delete records from multiple tables using a single delete statement. Is it possible ? If so please let me know the procedure.
    Kindly Help.
    Thanks,
    Alexander.

    Hi Tim,
    Syntax of DELETE statement does not allow for multiple tables to be specified in this way. Infact, none of the DMLs allow you to specify table names like this.
    Technically, there are other ways of deleting from multiple tables with one statement.
    1. "Use a trigger":
    What was probably meant by this is that you have a driving-table on which you create a on-delete trigger. In this trigger, you write the logic for deleting from other tables that you want to delete from.
    This does mean a one-time effort of writing the trigger. But the actual DML operation of deleting from all the tables would be simply triggered by a delete on driving-table.
    2. Dynamic SQL:
    Write a PL/SQL code to open a cursor with table-names from which you want the data to be deleted from. In the cursor-for loop, write a dynamic SQL using the table-name to delete from that table.
    3. Using Foreign-Key constraint with Cascade-Delete:
    This I feel is a more 'cleaner' way of doing this.
    Having to delete data from multiple tables means that there is some kind of parent-child relationship between your tables. These relationships can be implemented in database using foreign-key constraints. While creating foreign-key constraint give the 'on delete cascade' clause to ensure that whenever data is deleted from parent-table, its dependent data is deleted from child-table.
    Using foreign-key constraint you can create a heirarchy of parent-child relationships and still your DELETE would be simple as you would only have to delete from parent-table.
    IMPORTANT: Implementing foreign-key constraints would also impact other DML operations that you should keep in mind.

  • Delete records from internal table

    hi all,
    i want to delete records from intenal table which are starting with a particular starting number .
    eg internal table
    10000
    20000
    90000
    91000
    92000
    88880
    i want delete the records starting with 9 i.e. 90000 91000 92000.
    Thanks in Adv
            RAJ

    You can test this piece of code.
    DATA:
    i_tab TYPE STANDARD TABLE OF mara,
    wa_tab TYPE mara.
    wa_tab-matnr = '1000'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1002'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1003'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '2001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '3001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '4010'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Aug 8, 2008 4:49 PM

  • Delete records from a Table. Please help

    Hello Folks,
    I have a table that contains 7 records with a Button to delete each record.
    I am unable to delete any records from the table.
    Please can some one just have a look into my class and tell me how
    to delete a record from the table when the button is clicked.
    You can also run this class from the your command Prompt
    Just cut this and create a new java file.
    Please assist.
    Code Attached :
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    public class ButtonTableFactory {
    public static JTable createTable(Vector data, String buttonLabel, ActionListener action) {
    return createTable(data.iterator(), buttonLabel, action);
    public static JTable createTable(
    Iterator dataIterator,
    String buttonLabel,
    ActionListener action) {
    DefaultTableModel model = new DefaultTableModel() {
    public boolean isCellEditable(int row, int col) {
    return col == 1;
    model.setColumnCount(2);
    while (dataIterator.hasNext()) {
    Object[] row = { dataIterator.next().toString(), null };
    model.addRow(row);
    DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
    columnModel.addColumn(new TableColumn(0, 100));
    columnModel.addColumn(new TableColumn(1, 80,
    new TableButtonCellRenderer(buttonLabel),
    new TableButtonCellEditor(buttonLabel, action)
    JTable table = new JTable(model, columnModel) {
    public void valueChanged(ListSelectionEvent e) {
    super.valueChanged(e);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    return table;
    private static class TableButtonCellRenderer implements TableCellRenderer {
    final JButton button;
    TableButtonCellRenderer(String buttonLabel) {
    button = new JButton(buttonLabel);
    public Component getTableCellRendererComponent(
    JTable table,
    Object value,
    boolean isSelected,
    boolean hasFocus, int row, int column) {
    return button;
    private static class TableButtonCellEditor
    extends AbstractCellEditor
    implements TableCellEditor, ActionListener {
    final JButton button;
    final ActionListener callback;
    TableButtonCellEditor(String buttonLabel, ActionListener callback) {
    button = new JButton(buttonLabel);
    this.callback = callback;
    button.addActionListener(this);
    public Component getTableCellEditorComponent(
    JTable table,
    Object value,
    boolean isSelected,
    int row, int column) {
    return button;
    public Object getCellEditorValue() {
    return null;
    public void actionPerformed(ActionEvent e) {
    button.getParent().requestFocus();
    callback.actionPerformed(e);
    static JTable table;
    public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Vector items = new Vector();
    for (int i = 0; i < 7; i++) {
    items.add(Integer.toString(i));
    ActionListener al = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.out.println("You clicked row: " + table.getSelectedRow());
    table = ButtonTableFactory.createTable(items, "More:", al);
    frame.getContentPane().add(new JScrollPane(table));
    frame.pack();
    frame.show();

    This will get you closer:
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    public class ButtonTableFactory {
        private JTable table;
        private Vector items = new Vector();
        private JScrollPane scroll;
        private JPanel main;
        private ActionListener al;
        public static JTable createTable(Vector data, String buttonLabel, ActionListener action) {
            return createTable(data.iterator(), buttonLabel, action);
        public static JTable createTable(
                Iterator dataIterator,
                String buttonLabel,
                ActionListener action) {
            DefaultTableModel model = new DefaultTableModel() {
                public boolean isCellEditable(int row, int col) {
                    return col == 1;
            model.setColumnCount(2);
            while (dataIterator.hasNext()) {
                Object[] row = { dataIterator.next().toString(), null };
                model.addRow(row);
            DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
            columnModel.addColumn(new TableColumn(0, 100));
            columnModel.addColumn(new TableColumn(1, 80,
                    new TableButtonCellRenderer(buttonLabel),
                    new TableButtonCellEditor(buttonLabel, action)
            JTable table = new JTable(model, columnModel) {
                public void valueChanged(ListSelectionEvent e) {
                    super.valueChanged(e);
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            return table;
        private static class TableButtonCellRenderer implements TableCellRenderer {
            final JButton button;
            TableButtonCellRenderer(String buttonLabel) {
                button = new JButton(buttonLabel);
            public Component getTableCellRendererComponent(
                    JTable table,
                    Object value,
                    boolean isSelected,
                    boolean hasFocus, int row, int column) {
                return button;
        private static class TableButtonCellEditor
                extends AbstractCellEditor
                implements TableCellEditor, ActionListener {
            final JButton button;
            final ActionListener callback;
            TableButtonCellEditor(String buttonLabel, ActionListener callback) {
                button = new JButton(buttonLabel);
                this.callback = callback;
                button.addActionListener(this);
            public Component getTableCellEditorComponent(
                    JTable table,
                    Object value,
                    boolean isSelected,
                    int row, int column) {
                return button;
            public Object getCellEditorValue() {
                return null;
            public void actionPerformed(ActionEvent e) {
                button.getParent().requestFocus();
                callback.actionPerformed(e);
        public void init() {
            main = new JPanel();
            main.setLayout(new BorderLayout());
            for (int i = 0; i < 7; i++) {
                items.add(Integer.toString(i));
            al = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("You clicked row: " + table.getSelectedRow());
                    items.remove(table.getSelectedRow());
                    buildTable(items);
            buildTable(items);
        public void buildTable(Vector items) {
            table = ButtonTableFactory.createTable(items, "More:", al);
            scroll = new JScrollPane(table);
            main.removeAll();
            main.add(scroll);
            main.revalidate();
            main.repaint();
        public JPanel getContent() {
            return main;
        public static void main(String[] args) {
            ButtonTableFactory factory = new ButtonTableFactory();
            factory.init();
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(factory.getContent());
            frame.setSize(300, 300);
            frame.setVisible(true);
    //        frame.pack();
    //        frame.show();
    }

  • Create Trigger to insert records from one table to another

    I created the below trigger to move data from one table to another after records have been inserted from another table to that table. What I need done is that each time records have been inserted into TEST_TBL, one of these actions codes should be implimented: U-update, N-insert, D-delete and inserted into TEST_TBL1. But each time I run the script, I get bunch of errors. Please see the script below: - Your help will be appreciated.
    create or replace
    trigger POWER_tr
    after update or insert or delete ON test_tbl
    for each row
    begin
    if updating then
    insert into test_tbl1
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
    VALUES
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'U', sysdate);
    ELSif INSERTING then
    insert insert into test_tbl1
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
    VALUES
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'N', sysdate);
    ELSIF deleting then
    insert into test_tbl1
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
    VALUES
    (idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'D', sysdate);
    END IF;
    END POWER_tr;
    Thank you,
    Albert Zaza
    Edited by: azaza on Mar 1, 2009 4:14 PM

    Hello
    At the end of trigger show errors / and post what errors are you getting exactly?
    Here is a simple example for your reference, this will save old values in history table; you can replace it with new values if that's what do you want.
    CREATE OR REPLACE TRIGGER TRG_DU
       AFTER DELETE OR UPDATE
       ON EMPLOYEE    REFERENCING NEW AS New OLD AS Old
       FOR EACH ROW
    DECLARE
    BEGIN
       IF UPDATING
       THEN
          INSERT INTO employee_hist
            VALUES   ('UPDATE',
                      :OLD.empid,
                      :OLD.name,
                      :OLD.deptid);
       ELSIF DELETING
       THEN
          INSERT INTO employee_hist
            VALUES   ('UPDATE',
                      :OLD.empid,
                      :OLD.name,
                      :OLD.deptid);
       END IF;
    EXCEPTION
       WHEN OTHERS
       THEN
          -- Consider logging the error and then re-raise
          RAISE;
    END TRG_DU;
    /Regards
    Edited by: OrionNet on Mar 1, 2009 7:27 PM

  • How to delete records from MTL_SYSTEM_ITEMS table

    Hello Experts,
    BANNER
    =======
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    PL/SQL Release 8.1.7.4.0 - Production
    CORE     8.1.7.0.0     Production
    TNS for IBM/AIX RISC System/6000: Version 8.1.7.4.0 - Production
    NLSRTL Version 3.4.1.0.0 - Production
    I am working on Oracle Apps - 11.5.8 version.
    I have some doubts in deleting the records from MTL_SYSTEM_ITEMS table.
    There are few records which have junk characters and currently resides in table.
    I need to delete those records.
    But as per the approach; we should not delete any data directly from MTL table as it would cause huge impact.
    I have followed the below approach; but didnt worked out well.
    Script
    =======
    1)
    I have modified the below parameter in the MTL_SYSTEM_ITEMS_INTERFACE table --> SET_PROCESS_ID =0,TRANSACTION_TYPE ='DELETE',PROCESS_FLAG=1 .
    Apart from that; everything remains the same as in MTL_SYSTEM_ITEM table.
    2) Called the "Import Items" concurrent program.
    It got successfully completed. But record still exists in MTL_SYSTEM_ITEMS_INTERFACE table
    Your help is highly appreciated.
    Insert into MTL_SYSTEM_ITEMS_INTERFACE
       (SET_PROCESS_ID ,TRANSACTION_TYPE,PROCESS_FLAG ,INVENTORY_ITEM_ID, ORGANIZATION_ID, LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY, LAST_UPDATE_LOGIN,
    SUMMARY_FLAG, ENABLED_FLAG, DESCRIPTION, BUYER_ID, SEGMENT1, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE9, ATTRIBUTE15, PURCHASING_ITEM_FLAG, SHIPPABLE_ITEM_FLAG,
    CUSTOMER_ORDER_FLAG, INTERNAL_ORDER_FLAG, SERVICE_ITEM_FLAG, INVENTORY_ITEM_FLAG, ENG_ITEM_FLAG, INVENTORY_ASSET_FLAG, PURCHASING_ENABLED_FLAG,
    CUSTOMER_ORDER_ENABLED_FLAG, INTERNAL_ORDER_ENABLED_FLAG, SO_TRANSACTIONS_FLAG, MTL_TRANSACTIONS_ENABLED_FLAG, STOCK_ENABLED_FLAG, BOM_ENABLED_FLAG, BUILD_IN_WIP_FLAG,
    REVISION_QTY_CONTROL_CODE, CATALOG_STATUS_FLAG, RETURNABLE_FLAG, TAXABLE_FLAG, QTY_RCV_EXCEPTION_CODE, ALLOW_ITEM_DESC_UPDATE_FLAG, RECEIPT_REQUIRED_FLAG,
    RFQ_REQUIRED_FLAG, QTY_RCV_TOLERANCE, LIST_PRICE_PER_UNIT, PRICE_TOLERANCE_PERCENT, ENFORCE_SHIP_TO_LOCATION_CODE, ALLOW_SUBSTITUTE_RECEIPTS_FLAG,
    ALLOW_UNORDERED_RECEIPTS_FLAG, DAYS_EARLY_RECEIPT_ALLOWED, DAYS_LATE_RECEIPT_ALLOWED, RECEIPT_DAYS_EXCEPTION_CODE, RECEIVING_ROUTING_ID, LOT_CONTROL_CODE,
    SHELF_LIFE_CODE, SHELF_LIFE_DAYS, SERIAL_NUMBER_CONTROL_CODE, RESTRICT_SUBINVENTORIES_CODE, RESTRICT_LOCATORS_CODE, LOCATION_CONTROL_CODE, ACCEPTABLE_EARLY_DAYS,
    PLANNING_TIME_FENCE_CODE, LEAD_TIME_LOT_SIZE, ACCEPTABLE_RATE_INCREASE, ACCEPTABLE_RATE_DECREASE, PLANNING_TIME_FENCE_DAYS, END_ASSEMBLY_PEGGING_FLAG,
    REPETITIVE_PLANNING_FLAG, BOM_ITEM_TYPE, PICK_COMPONENTS_FLAG, REPLENISH_TO_ORDER_FLAG, ATP_COMPONENTS_FLAG, ATP_FLAG, WIP_SUPPLY_TYPE, PRIMARY_UOM_CODE,
    PRIMARY_UNIT_OF_MEASURE, ALLOWED_UNITS_LOOKUP_CODE, COST_OF_SALES_ACCOUNT, SALES_ACCOUNT, DEFAULT_INCLUDE_IN_ROLLUP_FLAG, INVENTORY_ITEM_STATUS_CODE,
    INVENTORY_PLANNING_CODE, PLANNING_MAKE_BUY_CODE, FIXED_LOT_MULTIPLIER, ROUNDING_CONTROL_TYPE, CARRYING_COST, POSTPROCESSING_LEAD_TIME, PREPROCESSING_LEAD_TIME,
    FULL_LEAD_TIME, MRP_SAFETY_STOCK_CODE, FIXED_DAYS_SUPPLY, RESERVABLE_TYPE, VENDOR_WARRANTY_FLAG, SERVICEABLE_COMPONENT_FLAG, SERVICEABLE_PRODUCT_FLAG,
    PREVENTIVE_MAINTENANCE_FLAG, PRORATE_SERVICE_FLAG, INVOICEABLE_ITEM_FLAG, INVOICE_ENABLED_FLAG, MUST_USE_APPROVED_VENDOR_FLAG, OUTSIDE_OPERATION_FLAG,
    COSTING_ENABLED_FLAG, AUTO_CREATED_CONFIG_FLAG, CYCLE_COUNT_ENABLED_FLAG, ITEM_TYPE, SHIP_MODEL_COMPLETE_FLAG, MRP_PLANNING_CODE, RETURN_INSPECTION_REQUIREMENT,
    EFFECTIVITY_CONTROL, CHECK_SHORTAGES_FLAG, EQUIPMENT_TYPE, WEB_STATUS, BULK_PICKED_FLAG, LOT_STATUS_ENABLED, SERIAL_STATUS_ENABLED, LOT_SPLIT_ENABLED,
    LOT_MERGE_ENABLED, DUAL_UOM_CONTROL, SERV_BILLING_ENABLED_FLAG, LOT_TRANSLATE_ENABLED, DEFAULT_SO_SOURCE_TYPE, CREATE_SUPPLY_FLAG)
    Values
       (0,'DELETE',1,464852, 102, TO_DATE('01/11/2007 16:15:11', 'MM/DD/YYYY HH24:MI:SS'), 3443, TO_DATE('08/24/2006 14:13:03', 'MM/DD/YYYY HH24:MI:SS'), 3443, 21069398,
    'N', 'Y', 'pentaseal 6 X 320 SL-807202 Klockner', 4223, '0006320161', 'No', 'No', 'MRPM', 'N', 'Y', 'N', 'N', 'N', 'N', 'Y', 'N', 'Y', 'Y', 'N', 'N', 'N', 'N', 'Y',
    'Y', 'Y', 1, 'N', 'Y', 'N', 'WARNING', 'Y', 'Y', 'N', 3, 0, 20, 'WARNING', 'Y', 'Y', 5, 5, 'WARNING', 3, 1, 2, 1825, 1, 2, 2, 2, 10, 4, 1, 0, 0, 1, 'B', 'N', 4, 'N',
    'N', 'N', 'N', 2, 'EA', 'EACH', 3, 12916, 14296, 'Y', 'Uncosted', 6, 1, 100, 1, 2, 0, 5, 50, 1, 20, 1, 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', 'N', 'Y',
    'CMPC', 'N', 3, 2, 1, 'N', 2, 'UNPUBLISHED', 'N', 'N', 'N', 'N', 'N', 1, 'N', 'N', 'INTERNAL', 'Y');---------

    Hi,
    You have to use the delete item utility of Oracle Inventory.
    Responsibility: Inventory Superuser or similar
    Navigation: Items -> Delete Items
    Enter a meaningful name in the Group field.
    Type - Item
    Select the organization you want to delete the item from.
    In the details section, enter the items you want to delete.
    Once all the items entered, click on the "Chcek Group" button. This will validate whether the items you have entered are eligible to delete (i.e. whether any child record such as transactions exist).
    It will submit a concurrent program and once the program finishes you will be able to see the result in the Results tab.
    Finally click on the "Delete Group" button to delete the eligible items.
    Thanks,
    PS.

  • Any way to restore deleted record from VBAP table.

    Hi Guru,
    Is their any way to restore deleted record from vabp.
    Back is taken but , All quality server back is taken, any way to restore only
    deleted VBAP data from all Back.
    Regards
    Durgesh

    Hi Sahu ji,
    you will not be able to get those records.
    Check this : If this issue is in Development than no need to worry.
    If in quality and production , then usually a copy of the system is there , and this can help you.
    Also , check is there any report that exports this data in some other form for backup.
    Hope it help you.

  • Maximum Open cursor  Exceeded error when deleting records from a table

    I have a strange problem.
    I have a table EMP_MASTER . Whenever I am trying to delete a record from this table, I am getting Maximum no. of open cursor exceeded error. But this error doesnot come when i delete from any other tables. And no. of open cursor is much lesser than OPEN_CURSOR parameter.
    All other tables (around 700) has foreign key constraint to this EMP_MASTER table for created_user paramater.
    Is it some thing like, when I am trying to delete a record from EMP_master, implicit cursor opens up and checks all referenced tables. and that limit gets exceeded ?
    Please help.
    Thanks,
    Raj

    Raji03 wrote:
    There is no trigger defined for this table.
    Is there a limit on which no.of references made to a column ? Because one column in this field, Emp no is being referenced in almost every other table. around 700 tables. Will it have any adverse effect ?That should have nothing to do with your problem directly. Again, those tables could have triggers defined on them and you are leaking cursors in one of those triggers (wild guess).
    An example of a table with many many others foreign key'd to it.
    create table parent_of_everything
       column1 number primary key
    insert into parent_of_everything select level from dual connect by level <= 1000;
    commit;
    --create 1000 tables all with foreign keys to the parent_of_everything
    begin
       for i in 1 .. 1000
       loop
          execute immediate 'create table child_' || i || ' (column1 number, column2 number, constraint child_' || i || '_fk foreign key (column1) references parent_of_everything (column1) on delete cascade)';
          execute immediate 'insert into child_' || i || ' select level, mod(level, ' || i || ') from dual connect by level <= 1000';
          commit;
       end loop;
    end;
    TUBBY_TUBBZ?delete parent_of_everything;
    1000 rows deleted.
    Elapsed: 00:02:53.03No problems were had (none were expected).
    Cleanup script.
    --remove the 1000 child tables
    begin
       for i in 1 .. 1000
       loop
          begin
             execute immediate 'drop table child_' || i || ' purge';
          exception when others
             then
                null;
          end;
       end loop;
    end;
    /

  • Deleting records from Z table via an ABAP

    Hello hoping someone can help me
    I am about to start writing an abap that will delete records from three seperate z tables that have been in there for over 18 months.
    Hoping that someone can give me a shove in the right direction to start me off as never had to do anything like this before.
    Iv had a search through the forum but cant seem to find what im after
    Thanks

    Hi,
    The below statement will do the purpose.
    DELETE zcustom FROM TABLE ITAB.

  • Deleting Records from Referential Tables

    Hi,
    Can anyone help me in deleting records from tables in a hierarcial manner. For e.g C refers B and B refers A. I need to delete data from all three tables related to a where clause in A.I tried using User_constraints and User_cons_columns views. But i am not able to find a hierarchial delete statement.
    Venkatesh

    Did you look into the option of specifying ON DELETE CASCADE for your foreign key constraints. That way, if you delete a
    row from the master table Oracle will automatically go and delete the child rows. Take a look at the following script.
    Here, when I delete a row from table A for NUM = 1 the child rows from table B (WHERE num = 1) are automatically deleted.
    drop table b
    drop table a
    create table a (num number, name varchar2(40))
    create table b (num number, name varchar2(40))
    alter table a add constraint pk_a primary key(num)
    alter table b add constraint fk_b_num foreign key (num) references a(num) on delete cascade
    insert into a values (1, 'Test#1')
    insert into a values (2, 'Test#2')
    insert into b values (1, 'Referes#1')
    insert into b values (2, 'Referes#2')
    select * from a
    select * from b
    delete from a where num = 1
    select * from a
    select * from b
    Sridhar,
    Thanks a lot for your help.My exact need was to delete records in 50 tables starting with the key table for a specific condition in the key table.
    Assume table A has 100 records,B 200 records,C 150 records,D 400 records, etc
    When i want to delete some records in table A, i will not be able to do that as child records exists in table B and this structure will carry on till that last table in my application. How do i delete those specific records
    Venkatesh

  • Deleting records from internal tabl

    Hi All,
    Here i need delete records from one internal table, from another internal table. both contains same field as name1, so here , i need to delete records from t_itab , the records which are existed in t_itab1.
    first internal table t_itab contains
    vinesh01
    vinesh02
    vinesh03
    vinesh04
    second internal table t_itab1 contains
    vinesh01
    vinesh02
    here i need to delte t_itab1 entries from t_itab.
    regards,
    vinesh.

    Hi,
    try this code.
    first internal table t_itab contains
    vinesh01
    vinesh02
    vinesh03
    vinesh04
    second internal table t_itab1 contains
    vinesh01
    vinesh02
    loop at t_itab1.
    loop at t_itab.
    if t_itab-name1 = t_itab1-name1.
    delete t_itab.
    (OR)
    delete itab where t_itab-name = t_itab1-name.
    endif.
    endloop.
    endloop.
    regards.
    sriram.

  • Writing trigger for DML tracking on three table

    Hello,
    I need help on how can i write a trigger for updating backup table on DML changes on source table.
    I have source table named APP_SOURCE and backup table name APP_BACKUP with same data and structure.
    On any DML on source table APP_SOURCE it corresponding backup table APP_BACKUP should also be updated with same number of record changes on any DML
    (insert/update/delete) to maintain data consistency on both tables
    For cross refernce all changed DML records on source table APP_SOURCE should be tracked and stored within third table APP_SOURCEDMLTRACK storing old value and new value data before and after dml changes on source table APP_SOURCE
    source table create script:
    CREATE TABLE APP_SOURCE
    RCN_ID VARCHAR2(23 BYTE),
    CRD_NUM VARCHAR2(23 BYTE),
    TRN_TYP VARCHAR2(10 BYTE),
    TRN_DTE DATE,
    REF_NUM VARCHAR2(23 BYTE),
    TRN_CRR VARCHAR2(3 BYTE),
    TRN_AMT NUMBER(24,6),
    BLL_CRR VARCHAR2(3 BYTE),
    BLL_AMT NUMBER(16,2),
    BSN_DTE DATE,
    BRN_S VARCHAR2(10 BYTE),
    ACC_NUM_S VARCHAR2(24 BYTE),
    BRN_D VARCHAR2(10 BYTE),
    ACC_NUM_D VARCHAR2(24 BYTE),
    SRL_NUM VARCHAR2(12 BYTE),
    DVI_TYP VARCHAR2(8 BYTE),
    ORG_MSG_TYP VARCHAR2(6 BYTE),
    ACQ_CDE VARCHAR2(15 BYTE),
    ACQ_BIN VARCHAR2(11 BYTE),
    REV VARCHAR2(1 BYTE),
    DBCR_FLG VARCHAR2(1 BYTE),
    ATM_FEE NUMBER(16,2),
    ATM_ID VARCHAR2(16 BYTE),
    INT_FEE NUMBER(16,2),
    TRM_ID VARCHAR2(10 BYTE),
    MCN_CDE VARCHAR2(40 BYTE),
    MCN_INF VARCHAR2(40 BYTE),
    PNT_RCN_ID NUMBER(12),
    FGN_KEY VARCHAR2(23 BYTE),
    ERR_CDE VARCHAR2(200 BYTE),
    JNK VARCHAR2(50 BYTE),
    CRD_USED VARCHAR2(10 BYTE),
    RES_CDE VARCHAR2(3 BYTE),
    REA_CDE VARCHAR2(4 BYTE),
    PRC_CDE VARCHAR2(10 BYTE),
    MCC VARCHAR2(4 BYTE),
    APP_CDE VARCHAR2(8 BYTE),
    ISS_INS_ID VARCHAR2(11 BYTE),
    ACQ_INS_ID VARCHAR2(11 BYTE),
    ACQ_NET_CDE VARCHAR2(20 BYTE),
    ISS_NET_CDE VARCHAR2(20 BYTE),
    INST_ID VARCHAR2(60 BYTE),
    FIID1 VARCHAR2(20 BYTE),
    FIID2 VARCHAR2(20 BYTE),
    SWT_FLE VARCHAR2(50 BYTE),
    VIS_FLE VARCHAR2(50 BYTE),
    VIS_FLE_MCHDTE DATE,
    VIS_FLE_EODDTE DATE,
    VIS_FLE_RCNTYP NUMBER(2),
    VIS_FLE_ACNTID VARCHAR2(35 BYTE),
    MAS_FLE VARCHAR2(50 BYTE),
    MAS_FLE_MCHDTE DATE,
    MAS_FLE_EODDTE DATE,
    MAS_FLE_RCNTYP NUMBER(2),
    MAS_FLE_ACNTID VARCHAR2(35 BYTE),
    TIE1_FLE VARCHAR2(50 BYTE),
    TIE1_FLE_SRC VARCHAR2(50 BYTE),
    TIE1_FLE_MCHDTE DATE,
    TIE1_FLE_EODDTE DATE,
    TIE1_FLE_RCNTYP NUMBER(2),
    TIE1_FLE_ACNTID VARCHAR2(35 BYTE),
    TIE2_FLE VARCHAR2(50 BYTE),
    TIE2_FLE_SRC VARCHAR2(50 BYTE),
    TIE2_FLE_MCHDTE DATE,
    TIE2_FLE_EODDTE DATE,
    TIE2_FLE_RCNTYP NUMBER(2),
    TIE2_FLE_ACNTID VARCHAR2(35 BYTE),
    TIE3_FLE VARCHAR2(50 BYTE),
    TIE3_FLE_SRC VARCHAR2(50 BYTE),
    TIE3_FLE_MCHDTE DATE,
    TIE3_FLE_EODDTE DATE,
    TIE3_FLE_RCNTYP NUMBER(2),
    TIE3_FLE_ACNTID VARCHAR2(35 BYTE),
    TIE4_FLE VARCHAR2(50 BYTE),
    TIE4_FLE_SRC VARCHAR2(50 BYTE),
    TIE4_FLE_MCHDTE DATE,
    TIE4_FLE_EODDTE DATE,
    TIE4_FLE_RCNTYP NUMBER(2),
    TIE4_FLE_ACNTID VARCHAR2(35 BYTE),
    TIE5_FLE VARCHAR2(50 BYTE),
    TIE5_FLE_SRC VARCHAR2(50 BYTE),
    TIE5_FLE_MCHDTE DATE,
    TIE5_FLE_EODDTE DATE,
    TIE5_FLE_RCNTYP NUMBER(2),
    TIE5_FLE_ACNTID VARCHAR2(35 BYTE),
    TIE6_FLE VARCHAR2(50 BYTE),
    TIE6_FLE_SRC VARCHAR2(50 BYTE),
    TIE6_FLE_MCHDTE DATE,
    TIE6_FLE_EODDTE DATE,
    TIE6_FLE_RCNTYP NUMBER(2),
    TIE6_FLE_ACNTID VARCHAR2(35 BYTE),
    EJ_FLE VARCHAR2(50 BYTE),
    EJ_FLE_MCHDTE DATE,
    EJ_FLE_EODDTE DATE,
    EJ_FLE_RCNTYP NUMBER(2),
    EJ_FLE_ACNTID VARCHAR2(35 BYTE),
    BTH_FLE VARCHAR2(50 BYTE),
    BTH_FLE_MCHDTE DATE,
    BTH_FLE_EODDTE DATE,
    BTH_FLE_RCNTYP NUMBER(2),
    BTH_FLE_ACNTID VARCHAR2(35 BYTE),
    BRN_ISS_FLE VARCHAR2(50 BYTE),
    BRN_ISS_FLE_MCHDTE DATE,
    BRN_ISS_FLE_EODDTE DATE,
    BRN_ISS_FLE_RCNTYP NUMBER(2),
    BRN_ISS_FLE_ACNTID VARCHAR2(35 BYTE),
    BRN_ACQ_FLE VARCHAR2(50 BYTE),
    BRN_ACQ_FLE_MCHDTE DATE,
    BRN_ACQ_FLE_EODDTE DATE,
    BRN_ACQ_FLE_RCNTYP NUMBER(2),
    BRN_ACQ_FLE_ACNTID VARCHAR2(35 BYTE),
    TRNACC_ID VARCHAR2(21 BYTE),
    PRT_TRNACC_ID VARCHAR2(35 BYTE),
    PROCESS_ID VARCHAR2(20 BYTE),
    SWT_VCH1_NUM VARCHAR2(100 BYTE),
    SWT_VCH2_NUM VARCHAR2(100 BYTE),
    SWT_VCH3_NUM VARCHAR2(100 BYTE),
    SWT_VCH4_NUM VARCHAR2(100 BYTE),
    SWT_VCH5_NUM VARCHAR2(100 BYTE),
    SWT_VCH1A_NUM VARCHAR2(100 BYTE),
    SWT_VCH2A_NUM VARCHAR2(100 BYTE),
    SWT_VCH3A_NUM VARCHAR2(100 BYTE),
    SWT_VCH4A_NUM VARCHAR2(100 BYTE),
    SWT_VCH5A_NUM VARCHAR2(100 BYTE),
    SWT_VCH1B_NUM VARCHAR2(100 BYTE),
    SWT_VCH2B_NUM VARCHAR2(100 BYTE),
    SWT_VCH3B_NUM VARCHAR2(100 BYTE),
    SWT_VCH4B_NUM VARCHAR2(100 BYTE),
    SWT_VCH5B_NUM VARCHAR2(100 BYTE),
    SWT_VCH1C_NUM VARCHAR2(100 BYTE),
    SWT_VCH2C_NUM VARCHAR2(100 BYTE),
    SWT_VCH3C_NUM VARCHAR2(100 BYTE),
    SWT_VCH4C_NUM VARCHAR2(100 BYTE),
    SWT_VCH5C_NUM VARCHAR2(100 BYTE),
    SWT_VCH1D_NUM VARCHAR2(100 BYTE),
    SWT_VCH2D_NUM VARCHAR2(100 BYTE),
    SWT_VCH3D_NUM VARCHAR2(100 BYTE),
    SWT_VCH4D_NUM VARCHAR2(100 BYTE),
    SWT_VCH5D_NUM VARCHAR2(100 BYTE),
    SWT_VCH1E_NUM VARCHAR2(100 BYTE),
    SWT_VCH2E_NUM VARCHAR2(100 BYTE),
    SWT_VCH3E_NUM VARCHAR2(100 BYTE),
    SWT_VCH4E_NUM VARCHAR2(100 BYTE),
    SWT_VCH5E_NUM VARCHAR2(100 BYTE),
    SWT_VCH1F_NUM VARCHAR2(100 BYTE),
    SWT_VCH2F_NUM VARCHAR2(100 BYTE),
    SWT_VCH3F_NUM VARCHAR2(100 BYTE),
    SWT_VCH4F_NUM VARCHAR2(100 BYTE),
    SWT_VCH5F_NUM VARCHAR2(100 BYTE),
    SWT_VCH1G_NUM VARCHAR2(100 BYTE),
    SWT_VCH2G_NUM VARCHAR2(100 BYTE),
    SWT_VCH3G_NUM VARCHAR2(100 BYTE),
    SWT_VCH4G_NUM VARCHAR2(100 BYTE),
    SWT_VCH5G_NUM VARCHAR2(100 BYTE),
    SWT_VCH1H_NUM VARCHAR2(100 BYTE),
    SWT_VCH2H_NUM VARCHAR2(100 BYTE),
    SWT_VCH3H_NUM VARCHAR2(100 BYTE),
    SWT_VCH4H_NUM VARCHAR2(100 BYTE),
    SWT_VCH5H_NUM VARCHAR2(100 BYTE),
    SWT_VCH1I_NUM VARCHAR2(100 BYTE),
    SWT_VCH2I_NUM VARCHAR2(100 BYTE),
    SWT_VCH3I_NUM VARCHAR2(100 BYTE),
    SWT_VCH4I_NUM VARCHAR2(100 BYTE),
    SWT_VCH5I_NUM VARCHAR2(100 BYTE),
    VIS_VCH_NUM VARCHAR2(100 BYTE),
    MAS_VCH_NUM VARCHAR2(100 BYTE),
    TIE1_VCH_NUM VARCHAR2(100 BYTE),
    TIE2_VCH_NUM VARCHAR2(100 BYTE),
    TIE3_VCH_NUM VARCHAR2(100 BYTE),
    TIE4_VCH_NUM VARCHAR2(100 BYTE),
    TIE5_VCH_NUM VARCHAR2(100 BYTE),
    TIE6_VCH_NUM VARCHAR2(100 BYTE),
    EJ_VCH_NUM VARCHAR2(100 BYTE),
    BTH_VCH_NUM VARCHAR2(100 BYTE),
    BRN_ISS_VCH_NUM VARCHAR2(100 BYTE),
    BRN_ACQ_VCH_NUM VARCHAR2(100 BYTE),
    PAR_DTE DATE,
    EOD_DTE1 DATE,
    EOD_DTE2 DATE,
    FILLER1 VARCHAR2(4000 BYTE),
    FILLER2 VARCHAR2(4000 BYTE),
    FILLER3 VARCHAR2(4000 BYTE),
    BRM_LINKID1 VARCHAR2(20 BYTE),
    BRM_LINKID2 VARCHAR2(20 BYTE),
    BRN_ACQ_FLE_ORG VARCHAR2(50 BYTE),
    CRM_TRACK_FLAG VARCHAR2(20 BYTE),
    DIFF_AMT NUMBER(16,2),
    IS_RCN NUMBER(1),
    MCH_DTE DATE,
    MIGRATION_FLAG VARCHAR2(50 BYTE),
    NET_CDE VARCHAR2(20 BYTE),
    TRACK_FLAG VARCHAR2(100 BYTE),
    TRN_MM VARCHAR2(2 BYTE),
    TRN_YY VARCHAR2(4 BYTE),
    MOVE_FLAG VARCHAR2(15 BYTE),
    PURGE_FLAG NUMBER(2),
    REV_FLAG NUMBER(1),
    TEMPVCH_LOCK_DTE DATE
    Please provide me any refernce on web or document which i can implement or code on how to code the required trgger.
    Regards,
    Ganesh

    Perhaps you should consider using Materialized View Replication.
    http://docs.oracle.com/cd/E11882_01/server.112/e10706/repoverview.htm#autoId9
    Instead of writing triggers, you put a materialized view log on your source table. Then you can turn your backup table into a materialized view that is based on the source table. When you perform a fast refresh of the backup table MV, it will read the MV log on the source table. Refreshes should take almost no time at all to process.
    If the data must be absolutely up-to-date at all times, you can use refresh on commit so that the MV is always in synch with the table. Normally I recommend against using refresh on commit, and instead recommend a short refresh interval.
    You can use triggers as you suggest, but it seems simpler to use something like MVs to create a shadow table.

  • Deleting records from compared tables...

    Hi all,
    I know there are a bunch of posts regarding this issue...but I don't see one that quite fits this scenario. I have two tables with the exact same structure...with key field matnr. I want to delete all of those records from table A where the material does NOT exist in table B. Is there a terse way to accomplish this?

    Suresh and Ravi,
    you are real good contributors to this forum and i like that.
    Not that you give a LOT of answers, your answers even porve quality.
    BUT i have one thing. People asking questions here are sometimes not TOO used to the ABAP syntax and other concepts.
    SAP noticed that themselves and made some concepts "obsolete", to get a code which is better to read. Especially for newbies.
    And well HEADER LINES are obsolete by now.
    People not beeing really used to ABAP will have really big Problems in reading things like:
    Loop at itab.
    endloop.
    or even harder:
    modify itab.
    this shall not be critic in any way, but rather a suggestion on how you can help the better. Accoring to your number of posts thats what you actually want.
    thx for convenience.

  • Deleting records from a table with 12 million records

    We need to delete some records on this table.
    SQL> desc CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak;
    Name Null? Type
    CLM_PMT_CHCK_NUM NOT NULL NUMBER(9)
    CLM_PMT_CHCK_ACCT NOT NULL VARCHAR2(5)
    CLM_PMT_PAYEE_POSTAL_EXT_CD VARCHAR2(4)
    CLM_PMT_CHCK_AMT NUMBER(9,2)
    CLM_PMT_CHCK_DT DATE
    CLM_PMT_PAYEE_NAME VARCHAR2(30)
    CLM_PMT_PAYEE_ADDR_LINE_1 VARCHAR2(30)
    CLM_PMT_PAYEE_ADDR_LINE_2 VARCHAR2(30)
    CLM_PMT_PAYEE_CITY VARCHAR2(19)
    CLM_PMT_PAYEE_STATE_CD CHAR(2)
    CLM_PMT_PAYEE_POSTAL_CD VARCHAR2(5)
    CLM_PMT_SUM_CHCK_IND CHAR(1)
    CLM_PMT_PAYEE_TYPE_CD CHAR(1)
    CLM_PMT_CHCK_STTS_CD CHAR(2)
    SYSTEM_INSERT_DT DATE
    SYSTEM_UPDATE_DT
    I only need to delete the records based on this condition
    select * from CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak
    where CLM_PMT_CHCK_ACCT='00107' AND CLM_PMT_CHCK_NUM>=002196611 AND CLM_PMT_CHCK_NUM<=002197018;
    Thsi table has 12 million records.
    Please advise
    Regards,
    Narayan

    user7202581 wrote:
    We need to delete some records on this table.
    SQL> desc CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak;
    Name Null? Type
    CLM_PMT_CHCK_NUM NOT NULL NUMBER(9)
    CLM_PMT_CHCK_ACCT NOT NULL VARCHAR2(5)
    CLM_PMT_PAYEE_POSTAL_EXT_CD VARCHAR2(4)
    CLM_PMT_CHCK_AMT NUMBER(9,2)
    CLM_PMT_CHCK_DT DATE
    CLM_PMT_PAYEE_NAME VARCHAR2(30)
    CLM_PMT_PAYEE_ADDR_LINE_1 VARCHAR2(30)
    CLM_PMT_PAYEE_ADDR_LINE_2 VARCHAR2(30)
    CLM_PMT_PAYEE_CITY VARCHAR2(19)
    CLM_PMT_PAYEE_STATE_CD CHAR(2)
    CLM_PMT_PAYEE_POSTAL_CD VARCHAR2(5)
    CLM_PMT_SUM_CHCK_IND CHAR(1)
    CLM_PMT_PAYEE_TYPE_CD CHAR(1)
    CLM_PMT_CHCK_STTS_CD CHAR(2)
    SYSTEM_INSERT_DT DATE
    SYSTEM_UPDATE_DT
    I only need to delete the records based on this condition
    select * from CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak
    where CLM_PMT_CHCK_ACCT='00107' AND CLM_PMT_CHCK_NUM>=002196611 AND CLM_PMT_CHCK_NUM<=002197018;
    Thsi table has 12 million records.
    Please advise
    Regards,
    NarayanDELETE from CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak
    where CLM_PMT_CHCK_ACCT='00107' AND CLM_PMT_CHCK_NUM>=002196611 AND CLM_PMT_CHCK_NUM<=002197018;

  • Delete records from z-table

    Hi ,
    delete statement is not working .
    i am using the logic like this .
    loop at itab into work_area.
    delete z-table from work_area .
    endloop.
    but i am unable to delete the records from the z-table .
    could you please look into this.
    Thanks,
    kumar.

    hi suresh,
    <b>DELETE  dbtab FROM wa.</b>
    After the statement is executed, the sytem field SY-DBCNT contains the number of lines that were deleted (0 or 1).
    The Return Code is set as follows:
    SY-SUBRC = 0:
    The line was deleted.
    SY-SUBRC = 4:
    No line could be deleted since there was no line with the primary key specified.
    example:
    <b>
    DATA wa TYPE sbook.
    wa-carrid = 'LH'.
    wa-connid = '0400'.
    wa-fldate = '20010228'.
    wa-bookid = '00000003'.
    DELETE sbook FROM wa.</b>
    check this link:
    http://help.sap.com/saphelp_47x200/helpdata/en/a6/0c723c590a9f6fe10000000a11405a/frameset.htm
    http://help.sap.com/saphelp_47x200/helpdata/en/a4/35ff395ef548e5add909b73ca12878/frameset.htm
    reward me if useful...
    Harimanjesh AN

Maybe you are looking for

  • How many computers can you get music from?

    How many different computers can you connect your ipod to and take music from?

  • Move Partition from HP Disks to HC Disks

    Dear All, We have Exadata -V2 quarter rack with High Performance Disks. We applied EHCC's various compression methods on some of the table's partitions. Now we are setting up Exadata Expansion Rack - High Capacity Disks. Post implementation, we would

  • Printing to a i560 on a windows PC

    I have set up my mac so that i can print to my canon i560. Seeing as there is no driver for my canon in the printer setup utility i have gone through the list and printed a page for each driver under Canon. I found that the s800 driver printed the do

  • Can't get Compressor to start

    Very frustrated, any ideas. I reinstalled the program and fixed the Qmaster thing. Here is the error report Thanks in advance Chris Process: Compressor [1075] Path: /Applications/Compressor.app/Contents/MacOS/Compressor Identifier: com.apple.compress

  • [solved] vconsole.conf FONT setting is not respected in systemd

    I recently converted my Arch system to a pure systemd setup (as described here), and everything seems to be working as before. Well, almost everything. Prior to switching over to systemd, I had already moved all config settings (except for the DAEMON