cuiyi's blog(崔毅 crazycy)

记录点滴 鉴往事之得失 以资于发展
数据加载中……

数据库触发器Trigger或者存储过程Procedure的调试技巧

use Print
PRINT 'testing----' WAITFOR DELAY '00:00:05';
程序中调用这个procedure或者触发这个trigger,java控制台根本没有这个输出;
很生气,后果很严重的让时间飞逝。

网上众多大拿推荐使用Raiserror,于是
raiserror ('test raiserror 1---'10-1with log

raiserror ('test raiserror 2---'101with nowait
程序中调用这个procedure或者触发这个trigger,java控制台根本没有这个输出;
很生气,后果很严重的让时间飞逝。

于是,很无语胡乱的测试:
raiserror ('test raiserror 3---'16,-1with log;
raiserror ('test raiserror 4---'16,-1with nowait;
任何一条都输出并且让程序回滚,很好很好

我得找到这个原因:
翻翻MSDN吧:
 A RAISERROR severity of 11 to 19 executed in the TRY block of a TRY…CATCH construct causes control to transfer to the associated CATCH block. Specify a severity of 10 or lower to return messages using RAISERROR without invoking a CATCH block. PRINT does not transfer control to a CATCH block.
好吧,10以上的数字才会强迫它工作。

但是呢,为了不抛错误,我们可以做以下2种方案:
方案一:
建立tmp表,利用insert保存你要的结果
方案二:
不知道try catch是不是能帮上忙,就留在下回测试吧。

f

posted on 2013-04-10 20:05 crazycy 阅读(1404) 评论(0)  编辑  收藏 所属分类: DBMS


只有注册用户登录后才能发表评论。


网站导航: