• Start by removing the BEGIN TRAN/COMMIT statements. They serve no use here because you have no error detection.

    Check your Java program... is it keeping a file open?

    Get rid of the WAIT FOR... it makes a long transaction even longer.

    Last but not least... if someone inserts 1000 rows and two of them have the same order number, BOOM! Code will fail because you try to put the order number into a variable which can only accept one row. This isn't like Oracle where you write a single row trigger and tell it FOR EACH ROW... all the rows you inserted are in a single INSERTED table. You will need to rewrite this trigger to be set-based instead of RBAR.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)