How can I implement the equivilent of a temporary table with "on commit delete rows"?

hi,
I have triggers on several tables. During a transaction, I need to gather information from all of them, and once one of the triggers has all the information, it creates some data. I Can't rely on the order of the triggers.
In Oracle and DB2, I'm using temporary tables with "ON COMMIT DELETE ROWS" to gather the information - They fit perfectly to the situation since I don't want any information to be passed between different transactions.
In SQL Server, there are local temporary tables and global.  Local temp tables don't work for me since apparently they get deleted at the end of the trigger. Global tables keep the data between transactions.
I could use global tables and add some field that identifies the transaction, and in each access to these tables join by this field, but didn't find how to get some unique identifier for the transaction. @@SPID is the session, and sys.dm_tran_current_transaction
is not accessible by the user I'm supposed to work with.
Also with global tables, I can't just wipe data when "operation is done" since at the triggers level I cannot identify when the operation was done, transaction was committed and no other triggers are expected to fire.
Any idea which construct I could use to acheive the above - passing information between different triggers in the same transaction, while keeping the data visible to the current transaction?
(I saw similar questions but didn't see an adequate answer, sorry if posting something that was already asked).
Thanks!

This is the scenario: If changes (CRUD) happen to both TableA and TableB, then log some info to TableC. Logic looks something like this:
Create Trigger TableA_C After Insert on TableA {
  If info in temp tables available from TableB
        Write info to TableC
   else
       Write to temp tables info from TableA
Create Trigger TableB_C After Insert on TableB {
  If info in temp tables available from TableA
        Write info to TableC
   else
       Write to temp tables info from TableB
So each trigger needs info from the other table, and once everything is available, info to TableC is written. Info is only from the current transaction.
Order of the triggers is not defined. Also there's no gurantee that both triggers would fire - changes can happen only to TableA / B and in that case I don't want to write anything to TableC.
The part that gets and sets info to temp table is implemented as temp tables with "on commit delete rows" in DB2 / Oracle.
What do you think? As I've mentioned, I could use global temp tables with a field that would identify the transaction, but didn't find something like that in SQL Server. And, the lifespan of local temp tables is too short.

Similar Messages

  • How can i write the trigger for Global Temporary Table

    Hi Grus,
    How can i write the trigger for Global Temporary Table.
    I was created the GTT with trigger using the below script .
    CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
    EMP_C_NAME VARCHAR2(20 BYTE)
    ON COMMIT PRESERVE ROWS;
    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE OR UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
    END;
    trigger was create successfully, but the wouldn't insert into to EMPNAME Table..
    Please guide whether am correct or not? if not kindly give a correct syntax with example
    Thanks in Advance,
    Arun M M

    BEGIN
    INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
    END;
    you are referencing old value in insert stmt.
    BEGIN
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    END;then run ur application it works fine...
    CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
    EMP_C_NAME VARCHAR2(20 BYTE)
    ON COMMIT PRESERVE ROWS;
    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE OR UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    dbms_output.put_line(:OLD.EMP_C_NAME||'yahoo');
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    dbms_output.put_line(:OLD.EMP_C_NAME);
    END;
    create table EMPNAME as select * from GLOBAL_TEMP where 1=2
    insert into GLOBAL_TEMP values('fgfdgd');
    commit;
    select * from GLOBAL_TEMP;
    select * from EMPNAME;
    output:
    1 rows inserted
    commit succeeded.
    EMP_C_NAME          
    fgfdgd              
    1 rows selected
    EMP_C_NAME          
    fgfdgd              
    1 rows selectedgot it Arun
    Edited by: OraclePLSQL on Dec 28, 2010 6:07 PM

  • How can we implement the currency translation in a query definition

    How can we implement the currency translation in a query definition and should it modified for each and every type of currencies

    hi rama krishna
    i think u can not get any translation in Query. this is only for het the report as it is there in tables. if u want to write a report take a help of the Abaper
    hope u goit,assign points if u ok for this
    thanks
    subbu

  • How can I implement the connection pool in my java stored procedure

    my java stored procedures (in database 'B') have to connect to another oracle database ,let's say 'A'. And how can I implement the behavior like the so-called connection pool in my java stored procedure in 'B', as below.
    1. database B, has 2 java stored procedures sp1 and sp2
    2. both sp1 and sp2 connects to databse 'A'
    whatever I call the sp1 and sp2 and the database 'A' always only one connected session from sp1 and sp2 in database 'B'.
    THANKS A LOTS...

    my problem is I have a lots of java stored procedures need to cnnect to the remote oracle db, and I hope the remote db can only have a connected session from my java stored procedures in my local db. I try as below
    class sp{
    static Connection conn=null; //the remote db connection,
    public static void sp1(){...}//procedure 1, using conn
    public static void sp2(){...}//procedure 2, using conn,too
    I can 'see' the 'conn' variable if I invoke the sp1() and sp2() from the same client application(maybe sqlplus). But if I invoke the sp1() from client 'A' and invoke sp2() from client 'B' then the sp1() and sp2() can not see the 'conn' variable for each other. I think it's because the two clients cause oracle to create two instances of the class 'sp' and the sp1() and sp2() located in different instance seperately. Thus the sp1() and sp2() can not see 'conn' for each other. They can only see its own 'conn'.
    To connect to the remote db from the java stored procedure is easy but is it possible to connect to the remote db via database link from the java stored procedure at my local db ? If so, then I also archive my goal .
    BTW , thanks a lots...
    andrew :-)

  • 2 different iphones have the same Apple ID, how can I change the apple ID on one of them but not delete the other iphone's data and media?

    2 different iphones have the same Apple ID, how can I change the apple ID on one of them but not delete the other iphone's data and media?

    You don't have to do anything with the first iPod that you don't use anymore. If you are planning on keeping it, put in a drawer in your house and forget about it.
    You don't need a second account to use with the new iPod. I use one Appl e ID and iTunes library for two iPods, and two iPad. I have different content on all four devices. You can select exactly what you want to sync to each device and it can be different content on all devices.

  • How can I obtain the primary key of a table for an entity relation?

    hello everybody
    I am doing a consultation to a table in my data base, good this table has alone two fields, the first one is the code or pk and the second one is the description, to be presisos they are names of city and code.
    From the beginning!!: This method this one in another class that is a Dialog that is going to call to the class SelecPlace ();
      SelecPlace sl = new SelecPlace();
    public void capturarLugar(){  //  Simple void method in the mentioned class
            String place = txtProcedencia.getText() ;  //  a JTextField
            sl.executeStatement(place) ;                  
        }ok, now we see part of the code of the class SelectPlace
    public class SelecPlace extends AbstractTableModel{
        Connection con = null;
        Statement sentencia = null ;
        ResultSet rs = null;
        ResultSetMetaData rsmd = null ;
        String[] nameColum = {} ;
        Vector datos = new Vector() ;
        public SelecPlace() { }
        public void executeStatement(String query){
          try{
             con = DBManager.getConnection() ;
             sentencia = con.createStatement(rs.TYPE_SCROLL_INSENSITIVE,
                                                                          rs.CONCUR_UPDATABLE) ;
             String sql = "select * from Place where descripcion like %"+query+"%'";
              rs = sentencia.executeQuery(sql) ;
              rsmd = rs.getMetaData();
              int nroColumnas = rsmd.getColumnCount() ;
              nameColum = new String[nroColumnas] ;
              //obtengo los nombres de columnas en cache
               for(int colum = 0; colum < nroColumnas; columna++){
                    nameColum[colum] = rsmd.getColumnLabel(columna + 1) ;
               datos = new Vector();
                while(rs.next()){
                    Vector newRow = new Vector();
                    for(int i = 0; i < getColumnCount(); i++){
                    newRow.addElement(rs.getObject("place_ID"));
                    newRow.addElement(rs.getObject("description"));
                    datos.addElement(nuevaFila);
                fireTableChanged(null);
            }catch(SQLException e){
                System.err.println(e);
                e.printStackTrace(System.err);
                System.out.println("error in statement");
            }catch(ClassNotFoundException cnfe){
                System.err.println(cnfe);
        }Ok, this code me works and I obtain in this case the field description of the table Place
    Now my question is, how can I obtain the primary field of my table?
    I need this value of this field that in the base of information in a bigint, and to take it to the first class before mentioned, for that I am working with a data base related

    Certain duffymo and everyone!!, good I give you my scheme:
    And generalizing my question, I want to obtain the value of the primary key of a table in the database, I obtain more values of the same row, but I need the primary key, and you see one with the primary key I want to turn a Long and it to insert with code java in foreign clave in another table of the database
    Good of this form I believe that it would not be breaking the integrity relacional of the tables

  • How can I connect the iTunes in my iPad (now with iOS7) to my Power PC Mac?

    How can I connect the iTunes in my iPad (now with iOS7) to my Power PC Mac?

    Nope, the top OS version for the IBM processor is 10.5.8, and under that version I can not update the iTunes further than the 10.6.3 :-(
    But that means the brand leaves a large chunch os costumers with still perfectly operating computers out of the loop on purpose, so to force us to upgrade computer?
    Not fair at all, both are legitimate Apple products, they should sync no matter what! The sad thing is theu used to, before I migrated to iOS7 on the iPad, move that I now regret...

  • In the iMovie 11 event library, how can I get the iPhoto video clips to combine with my camcorder pics listed below and in chronological order?

    In the iMovie 11 event library, how can I get the iPhoto video clips to combine with my camcorder pics listed below and in chronological order?

    Try forcing iPhoto to load the Library on the External Hard drive by launching it while holding down the Option key. Choose the Library on the External HD, and quit iPhoto, see if iMovie can see the Library with the iPhoto Videos contained inside.

  • How can i get the list of DB02's Table spaces-overview?

    Dear Experts,
           Could you help me about how can i get the list of DB02's Table spaces-overview? which function module can do it?
    Thanks a lot

    Hi,
    Execute this FM DB02_ORA_FILL_TD110
    U will get all the details of table spaces in the importing parameter TD110 of that FM.
    Reward if helpful
    Regards
    Vodka.

  • How can I change the tuning (pitch) of apple loops with logic?

    how can I change the tuning (pitch) of apple loops with logic? Is it possible at all ??? Cant get a clear information . I´m a user of Logic 9.14

    Thanks.....but... How to change the pitch within a song arrange, lets for example say the loop is in F in original tune and i want him to be played in the song arrange maybe in A.... when i draw it in the arrange window, the tune goes back to the original...

  • How can i check the realtime ability of my program with LV 6.1?

    Hi, i did use a PXI-6053E daq card with Labview RT 6.0.3, after upgrading to
    LV 6.1 the single scan vi in my control loop displays no error, if i put too
    much stuff in the loop. i check data remaining, everything exactly as in
    the example i attached. With Labview 6.0.3 i did use the opcode "read
    oldest" all the time and got a "1" at data remaining output if runnig too
    slow. How can i check the realtime ability of my Program with LV 6.1? The
    attached example is running with 35kHz and green RT-LED, even if i put a
    "wait 1 ms" in the loop.
    Thx4help.
    Joerg
    [Attachment Optimized HW Timed Loop.llb, see below]
    Attachments:
    Optimized_HW_Timed_Loop.llb ‏242 KB

    You should still be able to use the data remaining output of AI SingleScan to indicate that you are maintaining real-time as you did in LabVIEW 6.0.3. If this is not working properly for you, you might try wiping out the ni-rt folder on the RT system and re-installing the RT software on it through MAX on your host computer. Check the versions you have. If you are still seeing data remaining = 0 even when you are running your loop significantly slower than your scan rate, you might want to contact the LabVIEW RT group at National Instruments for additional assistance.

  • How can i know the Column Position in a table

    Dear all
    How can i know the Column position in a table ..
    For example :-
    I have a table
    Desc EMPLOYEES
    Empid
    Ename
    Sal
    I want to know the Empid is in 1st position , ename is in 2nd position and sal is in 3rd position .
    is it possible ?

    Hi
    SELECT * FROM ALL_TAB_COLUMNS WHERE
    TABLE_NAME ='EMPLOYEES' AND owner=<OwNeR nAmE> ;)

  • How can i avoid the pointer "unknown" in a picture with a person

    How can i avoid the pointer "unknown" in a picture with a person?

    In the Info Pane, close off the Faces section

  • Hi how can i implement the scenario.......plz reply asap.........

    HI folks,
    i have a typical problem in bex .
    my scenario is:i am having 2 values say 'x','y'.
    i want to implement a formula like x-y.
    if the x value is negative then i have to get the result as negative after the 'y' value get subtracted.if 'x' is positive, i have to get positive value after subtracting 'y' value.
    please let me know how can i implement this scenario in bex.
    by using a formaula or condition or anything else. please let me know clearly including the expression asap.
    Best reagards,
    ashok.

    answered

  • How can I implement the security ports..?

    How can I use the security ports and SSL through javamail..?
    Can someone tell me what are the necessary things to b done while connecting to "Gmail" through Javamail??....like how to authenticate..etc??
    Edited by: shyamwdr on May 20, 2008 6:21 AM

    Did you read the FAQ?

Maybe you are looking for

  • Regular expressions with boolean connectives (AND, OR, NOT) in Java?

    I'd like to use regular expression patterns that are made up of simple regex patterns connected via AND, OR, or NOT operators, in order to do some keyword-style pattern matching. A pattern could look like this: (.*Is there.*) && (.*library.*) && !((.

  • My iPod shuffle is not appearing in my iTunes?

    My Ipod shuffle is not appearing in Itunes any suggestions?

  • Realtek stereo mix driver missing - G72-b63NR

    After reinstallation of Win7, the stereo mix option is missing in control panel/sound/recording devices. The microphone option is there, and works, but I can't get the stereo mix back (can't record streaming, youtube, etc) I've attempted automatic up

  • Slow after make update to 10.5.2

    After I made update for Leopard 10.5.1 to 10.5.2 I get slow, that slow come when system login to profile, the Dock items appear immediately but the Top bar and desktop items take more than 5 min to appear and that is very bad, so is there solution fo

  • SOAP in Servlet

    Hello. I have a problem in Servlet for responding for a request. I think I succeeded getting the soap request in my servlet. And I'm stuck in sending my soap response back. Is there anybody tell me exactly how to send my javax.xml.soap.SOAPMessage in