locked
Try/Catch Finally block? RRS feed

  • Question

  • Does sql server supports 'Finally block'in query?


    Begin Try

       <try block>

    End Try

    Begin Catch

       <catch block>

    End Catch

     

    Begin Finally?

     <finally block>?

    End Finally?

     

    P.S = I am trying to use finally so that i can drop my temp. table.

     

    Suggestions?


    creativity..
    Monday, July 6, 2009 7:29 PM

Answers

  • No... T-SQL only support Try/Catch

    Begin Try
    End Try

    Begin Catch
    End Catch

    http://technet.microsoft.com/en-us/library/ms175976.aspx


    If you use a table variable, when the proc goes out of scope, so will the table. There is no need to drop. You should be able to do that in the try block.

    JP
    Monday, July 6, 2009 7:35 PM
  • I would use a table variable. That way, you don't need to worry about a drop statement.

    JP
    Monday, July 6, 2009 7:38 PM
  • The temp table will automatically drop. If you still want to do that, I would do it in the Try block


    AE, MCTS
    Monday, July 6, 2009 7:39 PM

All replies

  • No... T-SQL only support Try/Catch

    Begin Try
    End Try

    Begin Catch
    End Catch

    http://technet.microsoft.com/en-us/library/ms175976.aspx


    If you use a table variable, when the proc goes out of scope, so will the table. There is no need to drop. You should be able to do that in the try block.

    JP
    Monday, July 6, 2009 7:35 PM

  • No Finally in T-SQL.

    AE, MCTS
    • Edited by Abdshall Monday, July 6, 2009 7:41 PM
    Monday, July 6, 2009 7:36 PM
  • Thanks guys,, so if i have a temp table created in stored procedure, in order to drop it shud i code my drop statement inside another try/catch block??
    creativity..
    Monday, July 6, 2009 7:37 PM
  • I would use a table variable. That way, you don't need to worry about a drop statement.

    JP
    Monday, July 6, 2009 7:38 PM
  • The temp table will automatically drop. If you still want to do that, I would do it in the Try block


    AE, MCTS
    Monday, July 6, 2009 7:39 PM