【发布时间】:2013-08-25 00:05:17
【问题描述】:
Begin Try
Declare @SQL NVarchar(Max)='Exec [MyLinkedServer].master.dbo.sp_executesql N''Drop Table [tempdb].dbo.[T1]''';
Print @SQL;
Exec master.dbo.sp_executesql @SQL;
End Try
Begin Catch
Print Error_Message()
End Catch
当 MyLinkedServer 中不存在表 T1 时,上述脚本会失败 而不是被定向到 Catch 部分。 我错过了什么?
要明确一点:原始过程使用参数在过程内部动态构造@SQL。
谢谢!
【问题讨论】:
标签: sql-server try-catch dynamic-sql sp-executesql