Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Location
    Edmonton, Canada
    Posts
    72

    Unanswered: Explicit Transactions

    I have an cursor that loops 720 times.
    Each FETCH does 6 INSERTS.
    Each FETCH the 6 INSERTs a total of 200-300 records appended.

    Would explicit transactions speed up the cursor?

    In Oracle, I would keep track of how many times I've looped, and commit every nth time. I would put a catch remainder COMMIT at the end of the procedure.

    I've got the IF @@TRANCOUNT > 19 COMMIT TRAN (about 6k records), but say I had <= 19 remaining at the end of the cursor, how do you get those to commit? I tried to put an IF @@TRANCOUNT > 1 COMMIT TRAN, but that didn't work.

    What's a good @@TRANCOUNT to commit at in this case?

    Thanks crew,
    Carl

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Is it possible to transform the cursor to a set based operation which may optimize the operation. can you post your code?
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Carl, Oracle is cursor heavy, and often requires their use. SQL Server is optimized for set-based operations, and cursors are usually the worst method of managing data.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Jul 2004
    Location
    Edmonton, Canada
    Posts
    72
    I was able to go set based with the sub procedure at the prompting of you folks. Perhaps I can get rid of this cursor as well. If I can

    SELECT CASE x=y THEN INSERT INTO xyz (SELECT * from abc) END

    Can you do stuff like this?

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    INSERT INTO xyz
    SELECT *
    from abc
    where x=y

    ...but you should enumerate your columns and avoid the use of "select *..."
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •