Transaction handling in the deleting multiple tables.

Hi 
I have a process to delete data from multiple tables. When we delete a specific table, do we get into
any locking issues on the other tables, as the complete logic is in the
TRANSACTION block, but only one "IF" condition will be executed at any time.
Is this good, or Do I need to break each "DELETE Table Tx" to a separate procedure?
---Example is below with wrapper and called SP sample syntax.
CREATE PROC Proc1
AS
BEGIN
EXEC Proc2 'T1', 'Date1'
EXEC Proc2 'T2', 'Date1'
EXEC Proc2 'T3', 'Date1'
END 
GO
CREATE PROC Proc2 (@Table_name VARCHAR(10), @Date DATETIME)
AS
Begin
BEGIN TRY
BEGIN TRAN T1
IF @Table_name  = T1
BEGIN
DELETE from T1 where t1.Datex <= @Date
END
IF @Table_name  = T2
BEGIN
DELETE from T2 where t2.Datet2 <= @Date
END
IF @Table_name  = T3
BEGIN
DELETE from T3 where t3.Datet3 <= @Date
END
COMMIT TRAN T1
END TRY
BEGIN CATCH
--On error 
ROLLBACK Tran T1
END CATCH
END
THanks,
Krishna

Kris_DB_Architect,
Why are you using multiple IFs. Just use this:
ALTER PROC Krishna_Forum @TableName VARCHAR(100),@BranchID INT
AS
DECLARE @SQLStmt VARCHAR(500)
SET @SQLStmt='DELETE '+@TableName +' WHERE BranchID='+CONVERT(VARCHAR(2),@BranchID)
EXEC (@SQLStmt)
EXEC Krishna_Forum 'AccBanalce',1
I have used your object only as described in another thread created by you. I hope this would be easily understandable.
Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

Similar Messages

  • Transaction Handling - JDBC Receiver Adapter - Multiple SP Calls

    Hello,
    I have the following scenario:
    I send an XML-SQL structure with multiple statment elements (each of them calling a different stored procedure). A stored procedure raises an error back to the JDBC Receiver Adapter in case of error.
    Is it possible to have transaction handling in the JDBC Receiver to ensure:
    - Commit only after ALL stored procedures where succesful (no error risen during calls)
    - Rollback of ALL already called stored procedures in case an error has been risen
    How can I implement these requirements in the JDBC Receiver Adapter?

    One more comment, I have found the following info for JDBC Drivers:
    <i> "JDBC driver's default is to autocommit, meaning that the result of every SQL statement is permanent as soon as it is executed. This is why the course hasn't had to be concerned with transactions so far, and is perfectly acceptable in many cases."</i>
    So I think that each SP-Call is automatically commited in case autocommit on JDBC Driver Level is set to "true". Does anyone know where I can change these settings? Directly on JDBC Receiver Adapter or do I have to go to Visual Admin for those changes?

  • Need help in deleting multiple tables

    Hi,
    In one of my scenario i want to delete One record from the table, but there are some child and sub child exist for the table. And the on delete cascade is not set fro any of the table.
    Structure of my table,
    Table-1
    tab1_pk
    tab1_name
    Table-2
    tab2_pk
    tab1_pk
    Table-3
    tab3_pk
    tab2_pk
    i want to delete the record from Table-1 and all the related record of Table-2 and Table-3 in a single query.
    Plz help

    Dear 786725,
    What has just came to my mind at first sight is that you can create a trigger for your approach. I don't think that a single query will delete some rows from more than one table.
    Please go to the http://tahiti.oracle.com , select your database version and search for the after trigger. Hint: You may need to use the FOR EACH ROW clause and you again may need to use :old :new parameters in the trigger to have the information of what has just been deleted from the relevant table.
    Hope That Helps.
    Ogan
    Edited by: Ogan Ozdogan on 05.Ağu.2010 19:00
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7004.htm#SQLRF01405
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b31695/dialogs.htm#sthref454
    4.24 Create Trigger
    The following information applies to a trigger, which is which is a stored PL/SQL block associated with a table, a schema, or the database, or an anonymous PL/SQL block or a call to a procedure implemented in PL/SQL or Java. The trigger is automatically executed when the specified conditions occur.
    Schema: Database schema in which to create the trigger.
    Name: Name of the trigger. Must be unique within the database.
    Add New Source in Lowercase: If this option is checked, new text is entered in lowercase regardless of the case in which you type it. This option affects only the appearance of the code, because PL/SQL is not case sensitive in its execution.
    Trigger tab
    Trigger Type: The type of object on which to create the trigger: TABLE, VIEW, SCHEMA, or DATABASE. (The remaining items depend on the type of trigger.)
    Table Owner or View Owner: For a trigger on a table or a view, the name of the owner of the table or the view.
    Table Name or View Name : For a trigger on a table or a view, the name of the table or the view.
    Before or After: For a trigger on a table, select Before to cause the database to fire the trigger before executing the triggering event, or select After to cause the database to fire the trigger after executing the triggering event.
    Statement Level or Row Level: For a trigger on a table, Statement Level fires the trigger once before or after the triggering statement that meets the optional trigger constraint defined in the WHEN condition; Row Level fires the trigger once for each row that is affected by the triggering statement and that meets the optional trigger constraint defined in the WHEN condition.
    Insert, Update, Delete: For a trigger on a table or a view, Insert fires the trigger whenever an INSERT statement adds a row to a table or adds an element to a nested table; Update fires fire the trigger whenever an UPDATE statement changes a value in one of the columns specified in Selected Columns (or in any column if no columns are specified); Delete fires the trigger whenever a DELETE statement removes a row from the table or removes an element from a nested table.
    Referencing - Old: For a trigger on a table, the correlation names in the PL/SQL block and WHEN condition of a row trigger to refer specifically to old value of the current row.
    Referencing - New: For a trigger on a table, the correlation names in the PL/SQL block and WHEN condition of a row trigger to refer specifically to new value of the current row.
    Available Columns: For a trigger on a table, lists the columns from which you can select for use in an Update trigger definition.
    Selected Columns: For a trigger on a table, lists the columns used in an Update trigger definition.
    When: For a trigger on a table, an optional trigger condition, which is a SQL condition that must be satisfied for the database to fire the trigger. This condition must contain correlation names and cannot contain a query.
    Schema: For a trigger on a schema, the name of the schema on which to create the trigger.
    Available Events: For a trigger on a schema or database, lists events from which you can select for use in the trigger definition.
    Selected Events: For a trigger on a schema or database, lists events used in the trigger definition.
    DDL tab
    This tab contains a read-only display of a SQL statement that reflects the current definition of the trigger.
    "

  • Php deleting multiple table using join

    Hi
    I have three tables called  Users, Photolevel and  Photostatus.  In the Users table I have  an activekey colunm which is 1 or 0. When its 1 the user is not active when 0 the user is active.
    I would like to delete all unactive users from the Users database and from Photolevel , Photostatus.
    I have tried a table join with delete which is not working. can any one help.
    Photolevel.useid and Photostatus.useid should join and be delete to the Users table where activekey is 1.
    Heres the code.
    $dbclean=mysql_query("DELETE Users.id, Users.username, Users.surname, Users.email, Users.gender, Users.age, Users.password,
    Users.country, Users.city, Users.profilepic,
    Users.activecode, Users.activekey, Users.DOB, Users.Date, Photolevel.pid, Photolevel.useid,
    Photolevel.genre, Photolevel.start, Photolevel.end, Photostatus.stuid, Photostatus.useid, Photostatus.vgenre
    FROM Users, Photolevel, Photostatus WHERE
    Users.id = Photolevel.pid AND
    Photolevel.pid = Photostatus.stuid AND
    Users.activekey='1'");

    >$sqlgo = mysql_query("DELETE FROM Users.id, Users.activekey, Photolevel.pid, Photolevel.useid, Photolevel.genre, Photolevel.start, Photolevel.end FROM Photolevel INNER >JOIN
    >Users ON Photolevel.useid=Users.id and Users.activekey='1' and Photolevel.genre='Photolevel.genre'");
    Again, your syntax is incorrect. You do not specifiy a column list in a delete statement. If you want to delete rows from a table, you specify the table name after the DELETE operator. You can then qualify which rows to delete using joins in the FROM clause and/or conditions in the WHERE clause.
    $sqlgo = mysql_query("DELETE Photolevel FROM Photolevel INNER JOIN Users ON Photolevel.useid=Users.id and Users.activekey='1' ");
    This statement yields the same results as the one I provided earlier that used the subquery.
    >and Photolevel.genre='Photolevel.genre'");
    I'm not sure what you are trying here. A column always equals itself so that condition will always evaluate as TRUE.

  • How do I check the delete database table is successful?

    After delete all the records from the database table, how do I check it is successful?  When do I need to 'commit'?  (after delete table or after insert new data?)
    Thanks,
    Helen

    Hi,
      Check sy-subrc = 0..
      DELETE ZTABLE..OR INSERT ZTABLE...
      IF SY-SUBRC <> 0.
        MESSAGE E000 WITH 'DATABASE DELETE FAILED'.
      ELSE.
        COMMIT WORK...
      ENDIF.
    Thanks,
    Naren

  • Transaction Handling across Procedures

    In the ODI Best Practice Guide for Data Warehouses I came across the following (page 100):
    "ODI procedures include an advanced mechanism for transaction handling across multiple steps or even multiple procedures."
    It states that transaction handling can occur across multiple procedures. I could not get this to work.
    I created a procedure with just one step that inserts into a table. In the step I have set the Transaction dropdown to Transaction 0 and the Commit dropdown to No Commit. However, when I execute the procedure the insert is committed as we terminate the session.
    Any ideas how this commit can be prevented?

    ok, I figured out that parameters to the JDBC driver can be specified at the properties tab of the data server.
    So I presume this will be autocommit = false or sth. similar
    I still have to try this out.

  • Context index can't be used in complicated multiple tables join?

    hello
    thank you for view this page.
    i have a comlicated sql :
    SELECT count(*)
    from
    ((app_AssetBasicInfo left join app_AssetBasicInfoExt on
    app_AssetBasicInfo.id=app_AssetBasicInfoExt.id) left join
    (app_AssetCustominfo1 left join app_AssetCustominfoExt1 on
    app_AssetCustominfo1.id=app_AssetCustominfoExt1.id) on
    app_AssetBasicInfo.id=app_AssetCustominfo1.id) WHERE
    app_AssetBasicInfo.CategoryID=1 AND Del_tag=0 and contains(description,'department')>0;
    the table app_AssetBasicInfo and app_AssetBasicInfoExt have multiple columns and large recoord size. i create a context index on app_assetbasicinfoext(description) which description is 4000 varchar2.
    but the sql doesn't use context index. i suspect that the complicated multiple table join can't use context index? does it correct?
    thanks very much!

    Could you please post an explain plan? I'm not quite sure what is the issue.

  • How to know the type of transactions by seeing the data in IP_IN_QUEUE

    Hi B2B gurus,
    I am Using EDI X12 over internet. Our suppliers processing inbound transactions to us,After receiving from B2B its storing in IP_IN_Queue, The documents which we are sending it storing in IP_OUT_Queue.
    We want to see the data in in IP_IN_QUEUE, Could you please tell in which table the data will store, And can we see the payload or can we know actually which transactions by seeing the data in table? Could you please help by giving this information...?
    regards
    srinivas k

    As I mentioned earlier view "b2b_instancemessage" has "payload" column which stores the payload of both incoming and outgoing messages.
    Below query will return all the rows of this view which has payload -
    select * from b2b_instancemessage where payload is not null;
    Remember, it's a BLOB type field so either use a client like PL-SQL Developer or TOAD otherwise write a java client to view the content of this column.
    Regards,
    Anuj

  • Transport Error - Deletion of Table Maintenance

    Hi Experts,
    I have been searching SDN, but I cannot find a specific problem relating to mine.
    My problem is, i am deleting a table, where a table maintenance was generated. Somehow, an error occurred during transport - it says 'Screen SAPLXXXXX 00XX: Generation error'. This is the screen for the table maintenance generated. Further on, I found that there is a syntax error, which is because it is referring to the table and its fields which were already deleted in the same transport.
    Question is, is the procedure wrong? Should I have deleted the Table Maintenance first and transport and then create transport for the deletion of table? How to correct the above error, when the table is already deleted?
    Thank you in advance for your help.
    Regards,
    Joy

    Hi ,
    Try to delete the Table maintainace first and then  try to delete Objects for Table maintainace in Transport.
    Then try to create a fresh table maintaiance with Proposed screens then it will work properly.
    Prabhduas

  • How to handle multiple tables data in Entity Beans?

    How to handle multiple tables data in Entity Beans?
    i mean, my bean (non trivial) is responsible for frequent
    insertion in one table and some deletion on another table.
    Can anyone of you...please..?

    Is your data model right? If you are adding in one and deleting in another it sounds to me more like a process that an entity, in which case you may revisit your data model and simplify it, add in a session bean with the process method to co-ordinate between the two.
    However, if you want to map multiple different tables within a single entity bean it is possible and just part of the mapping. How you actualyl specify it depends on which implementation you are working with.
    Cheers,
    Peter.

  • What's the best way to handle the growth of the mdm.tblTransaction table?

    Can anyone suggest a good way to handle the growth of the mdm.tblTransaction table? This table logs all the MDS transactions and the history of the data residing in it is required for auditing purposes. Hence we can't delete this data. I'm looking for options
    on how we can maitain this table ongoing. It is going to perform badly eventually. We currently have 15 Million transactions in this table.
    What options can we look at?

    In the vnext sql server, MDS will support cleaning based on log retention policy.
    In the sql2014/sql2012, you have to clean up the table manually.
    An sample sproc that can be reused is attached below.
    ==============================================================================
    Copyright (c) Microsoft Corporation. All Rights Reserved.
    ==============================================================================
    SELECT * FROM mdm.tbl_7_TR where LastChgDTM < '2014-10-22';
    EXEC mdm.udpLogCLeanup 7, '2014-10-22';
    SELECT * FROM mdm.tbl_7_TR where LastChgDTM < '2014-10-22';
    CREATE PROCEDURE mdm.udpTransactionsCleanup
    @Model_ID INT,
    @CleanupOlderThanDate DATE
    WITH EXECUTE AS N'mds_schema_user' -- Execute as a user that has permission to select on [tblUserGroupAssignment], [tblBRBusinessRule], [udfSecurityUserBusinessRuleList]
    AS BEGIN
    SET NOCOUNT ON
    DECLARE
    @SQL NVARCHAR(MAX)
    --Annotation table names
    ,@TransactionTableName sysname
    ,@AnnotationTableName sysname;
    SET @TransactionTableName = 'tblTransaction';
    SET @AnnotationTableName = 'tblTransactionAnnotation';
    BEGIN TRY
    --Delete all Annotations on transactions being deleted issues
    SET @SQL = N'
    DELETE [mdm].' + QUOTENAME(@AnnotationTableName) + N'
    FROM [mdm].' + QUOTENAME(@AnnotationTableName) + N' as tannt
    JOIN [mdm].'+ QUOTENAME(@TransactionTableName) + N' as txn ON tannt.Transaction_ID = txn.ID
    JOIN [mdm].[tblModelVersion] as tmv ON txn.Version_ID = tmv.ID
    WHERE tmv.Model_ID= @Model_ID AND txn.LastChgDTM <= @CleanupOlderThanDate
    EXEC sp_executesql @SQL, N'@Model_ID INT, @CleanupOlderThanDate DATE', @Model_ID, @CleanupOlderThanDate;
    --Delete all transactions older than the specified date
    SET @SQL = N'
    DELETE [mdm].' + QUOTENAME(@TransactionTableName) + N'
    FROM [mdm].' + QUOTENAME(@TransactionTableName) + N' txn
    JOIN [mdm].[tblModelVersion] tmv ON (txn.Version_ID = tmv.ID)
    WHERE tmv.Model_ID = @Model_ID AND txn.LastChgDTM <= @CleanupOlderThanDate
    EXEC sp_executesql @SQL, N'@Model_ID INT, @CleanupOlderThanDate DATE', @Model_ID, @CleanupOlderThanDate;
    RETURN(0);
    END TRY
    --Compensate as necessary
    BEGIN CATCH
    -- Get error info
    DECLARE
    @ErrorMessage NVARCHAR(4000),
    @ErrorSeverity INT,
    @ErrorState INT;
    EXEC mdm.udpGetErrorInfo
    @ErrorMessage = @ErrorMessage OUTPUT,
    @ErrorSeverity = @ErrorSeverity OUTPUT,
    @ErrorState = @ErrorState OUTPUT;
    RAISERROR(@ErrorMessage, @ErrorSeverity, @ErrorState);
    --On error, return NULL results
    --SELECT @Return_ID = NULL;
    RETURN(1);
    END CATCH;
    SET NOCOUNT OFF
    END --proc
    GO

  • Insert to multiple tables while keeping the referential integrity

    I would like to confirm whether we can have both updatable and reference for secondary entity. It seems to me that even though both updatable and reference can be checked for secondary entity, the secondary entity is not updatable.
    There are some scenarios that I hope to create the "parent" and "child" at the same time in the UI. For example, Employee and ProductExpertise which is in m:m relationship. We have three tables: Employee, EmployeeProduct, and Product. We have two view object, EmployeeVO which contains EmployeeEO, EmployeeProductVO which contains EmployeeProductEO and ProductEO. This can display EmployeeVO as master, and EmployeeProductVO as detail. However when we add a new product for the employee, we can only associate an existing product. We would like to create a new product and associate the product with employee. This cannot be achieved by the current EmployeeProductVO.
    I wonder if ADF supports inserting to multiple tables while keeping the foreign key reference integrity? In other words, in a 1:1..* (1 to 1 or 1 to many) relationship, must we have a master-detail view where we add parent first, then add child? Does ADF support adding both parent and child together with the correct foreign key assigned automatically for the child? Do we need to write code to do it?
    Any insight is appreciated.

    Hi,
    Assuming you are talking about ADF Business Components, yes, the framework can handle a batch insert that inserts both parent and child records in the same transaction. A few things that you may want to review:
    1). If you are using a database sequence for your primary keys (your question "Does ADF support adding both parent and child together with the correct foreign key assigned automatically for the child" made me think perhaps you were), have a read of the Fusion Developer's guide about the DBSequence type.
    2). In the same guide, have a read of section 38.8 - it talks about the small bit of code you may need to write to ensure the parent record is posted before the children, and also discusses about associations that are based on DB Sequences.
    Best,
    John

  • How to pass the single/multiple selected data of a table to SAP(R/3)

    Hi ,
    I have a table with 2 colums and 10 records.Now i want to send the selected record/Multiple records to the R/3.
    Once the user checks the checkbox i retrieved the column values of that row/rows into a string array.
    and i added all the string arrays to an AbstractList.
    Now in function module it is giving as setT_TestOperations(AbstractList)
    can any one help as  how the function module understands the individual/multiple String arrays.
    If possible provide sample code for the same.
    Thanks and regards,
    Chandrashekar.

    One way to achieve this is to maintain an attribute in the assistance class or a node element , called OldLeadSelection , at the Component controller level which stores the value of the lead selection index.
    On LeadSelect action handler method, in the first line, read the value of the attribute/element defined above. For the first time a row is lead selected, this value will be initial. After exexcuting the code in the LeadSelection event handler method, store the LeadSelection index value in the attribute defined above. The next time when the LeadSelection event method is called, when the value of this attribute is read in the initial line, it will house the value of the index of the previous LeadSelection.
    There could be other ways to achieve this. This is one of the methods.
    Best Regards,
    Rashmi.

  • Multiple transactions control in the same page

    I am using the Jdev11g 11.1.1.4 and ADF BC,
    I am quite new for Jdev11g, My question is I have a page, there are a af: form region and two af:table regions inside the same page.
    the 'master' is in af:form and two its 'details' are in either af:table.
    I want the user can commit the editing of af:form without affecting the af:tables, and also, for each af:table, user can 'edit', 'add', 'delete' and commit it without affecting the af:form and the other af:table.
    I know I can use the 'bound task flow' and build three regions to do so, but i have no experience about this, can you expert give me some idea or some sample link? Thanks!
    Edited by: xsyang on Jun 2, 2011 12:56 AM

    Hi,
    there are two good videos from Frank N.
    [url http://blogs.oracle.com/jdeveloperpm/entry/everything_you_wanted_to_know] Everything you wanted to know about ADF Task Flows .
    "Taskflow-Transaction" and "shared data controls with calling task flow" vs. "isolated data controls.." are the topics on which you should look.
    Martin

  • To delete multiple entries in table control in module pool

    Hi,
    Please help me out to know , <b>how to delete multiple entries from table control</b> when multiple lines in table control are selected.
    Regards,
    Irfan Hussain

    hai,
        you can do it inthis way.
    in the PAI event.
    loop at <table control name>
      module del_itab.
    endloop.
    in the nodule,write the folowing code.
    if <tablecontrol>-fieldname = 'X'.
    delete <tablecontrol-itab>
    endif.
    cheers

Maybe you are looking for

  • Return PO box ticked for return PO document type

    HI All, There is a help need for Badi.  While creating a return PO in T Code ME21N, i want to get return PO field  ( EKPO-RETPO) box ticked for Return PO document type. I found one BADI for ME_COMMITMENT_RETURN. I need help to use this badi. Regards,

  • Problem install windows on mid 2010 MacBook Pro 13 with 10.9.1

    I run into problem install windows on mid 2010 MacBook Pro 13 with 10.9.1.  Boot Camp Assistant shows error "Can't install the software because it is not currently available from the Software Update server.".  So what is the problem and how can I wor

  • Outbound SSO

    Hi I am developing a system for a client that integrates with their Siebel CRM On Demand. I have got everything working using usernaqme / password login to get a jsessionid and call services. But it would be better if we could use the SSOToken that c

  • Why not a LinkedMap interface for LinkedHashMap?

    I`m currently cleaning my null-rejecting collection framework and I found the LinkedHashMap in the Collection framework. Why doesn`t this class have an interface LinkedMap? The autor of the class, Joshua Bloch, tells in his 'Effective Java: Programmi

  • What happen to front row when i went to mountain lion?

    What happen to front row when I went to mountain lion?