具有多个更新、插入和删除的存储过程。如果最后一个 DML 命令失败会怎样?

Stored procedure with multiple updates, insert and deletes. What happens if last DML command fails?

所以,如果我在 SQL 服务器的存储过程中有多个 DML 命令,如果最后一个失败,所有其他的都会回滚吗?考虑到我不在交易范围内!

您需要存储过程才能使用 TRY CATCH 和 TRANSACTION。

BEGIN TRAN
BEGIN TRY

    COMMIT TRANSACTION
END TRY
BEGIN CATCH
    -- if error, roll back any changes done by any of the SQL statements
    ROLLBACK TRANSACTION
END CATCH

参考这个 http://techfunda.com/howto/192/transaction-in-stored-procedure