gpt4 book ai didi

sql-server-2008 - 如何使用 try、throw 和 catch 在错误处理中打印消息

转载 作者:行者123 更新时间:2023-12-04 07:04:16 25 4
gpt4 key购买 nike

我想在我的查询中打印一条消息(“数据库中不存在员工表”)。

我的查询是:

create proc sp_emprecord
as
begin
select * from employe
end

begin try
execute sp_emprecord
end try

begin catch
select
error_message() as errormessage,
error_number() as erronumber,
error_state() as errorstate,
error_procedure() as errorprocedure,
error_line() as errorline;
end catch

最佳答案

尝试这个:

create proc sp_emprecord
as
begin
select * from employe
end
go
begin try
execute sp_emprecord
end try

begin catch
if(ERROR_NUMBER() = 208)
RAISERROR ('The table employe is not exist in database', 0, 1) WITH NOWAIT;
else
select
error_message() as errormessage,
error_number() as erronumber,
error_state() as errorstate,
error_procedure() as errorprocedure,
error_line() as errorline;
end catch

关于sql-server-2008 - 如何使用 try、throw 和 catch 在错误处理中打印消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12317561/

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