抛出声明前的分号

时间:2018-01-07 21:02:49

标签: sql-server

1 个答案:

答案 0 :(得分:4)

它可以解决一些含糊不清的问题

比较

BEGIN TRAN THROW --Starts a transaction named "THROW"
BEGIN TRY
    SELECT 1 / 0
END TRY

BEGIN CATCH
    ROLLBACK TRAN
    THROW /*Rolls back the transaction named "THROW"*/
END CATCH 

BEGIN TRAN THROW --Starts a transaction named "THROW"
BEGIN TRY
    SELECT 1 / 0
END TRY

BEGIN CATCH
    ROLLBACK TRAN; /*rolls back the tran without caring about the name*/
    THROW --rethrows the error
END CATCH