我试图在异常发生后打印SP执行范围内的所有变量,以便对故障期间发生的错误有更多了解。你该怎么做?
BEGIN TRY
DECLARE @Var1 AS VARCHAR(MAX) = 'variable 1'
DECLARE @Var2 AS INT = 5
END TRY
BEGIN CATCH
SELECT @ErMessage = ERROR_MESSAGE(),
@ErSeverity = ERROR_SEVERITY(),
@ErState = ERROR_STATE();
RAISERROR(@ErMessage, @ErSeverity, @ErState);
-- Print all @variable values like "@Var1: variable 1, ..."
RETURN -1
END CATCH