SQL Server TRY CATCH FINALLY

前端 未结 6 2044
执笔经年
执笔经年 2021-02-06 23:09

I have a scenario where I need something similar to .NET\'s try-catch-finally block.

On my try, I will CREATE a #temp table, INSERT

6条回答
  •  孤独总比滥情好
    2021-02-06 23:47

    Instead of creating a table you could just declare a table variable (which will automatically go away when the query ends).

    BEGIN TRY
    DECLARE @temp TABLE
    (
        --columns
    )
    --do stuff
    END TRY
    BEGIN CATCH
    --do other stuff
    END CATCH
    

提交回复
热议问题