在Visual Studio 2008中,我可以使用CTRL + D + E进行选择,以使调试器在异常时中断,而不管是否存在catch块。
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9zNU5ocy5wbmcifQ==” alt =“在此处输入图像描述”>
SQL Server 2008 R2 Management Studio中是否有类似的选项,其中存储过程的执行将在引发错误时中断?
使用尝试捕获事务。例如:
create proc procexmaple (@parameter int)
as
begin try
begin transaction
select * from Employees where LastName = @parameter --this is an error converting nvarchar to int
commit transaction
end try
begin catch
select * from [Orders] where OrderID = @parameter -- the catch will work and this will run
rollback
end catch
go
如果您要建立自己的错误,也可以看到如何使用raiserror:
https://www.sqlservertutorial.net/sql-server-stored-procedures/sql-server-raiserror/