gpt4 book ai didi

sql-server-2008 - SQL Server 2008 R2 Management Studio调试: How to break at an exception?

转载 作者:行者123 更新时间:2023-12-04 06:57:51 27 4
gpt4 key购买 nike

在 Visual Studio 2008 中,我可以使用 CTRL+D+E 选择让调试器在异常点中断,无论是否有 catch block 。

enter image description here

SQL Server 2008 R2 Management Studio 中是否有类似的选项,存储过程的执行将在抛出错误时中断?

最佳答案

在事务中使用 try 和 catch。例如:

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/

关于sql-server-2008 - SQL Server 2008 R2 Management Studio调试: How to break at an exception?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16655871/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com