sqlserver 中使用print输出时如何能够立即看到


No. They will only be returned when a transaction is committed, when other record sets are returned or a statement is completed (go statement terminator in a SQL batch). You can use raiserror at non-fatal error levels (0-18) to get immediate feedback of this sort. For example:

RAISERROR ('Foo', 10, 1) WITH NOWAIT

使用raiserror函数进行输出,注意指定的错误为非致命性错误(raiserror中的第二个参数表示错误等级)(non-fatal error levels (0-18) 








down vote accepted

Use the RAISERROR function:

RAISERROR( 'This message will show up right away...',0,1) WITH NOWAIT

You shouldn't completely replace all your prints with raiserror. If you have a loop or large cursor somewhere just do it once or twice per iteration or even just every several iterations.

Also: I first learned about RAISERROR at this link, which I now consider the definitive source on SQL Server Error handling and definitely worth a read:
http://www.sommarskog.se/error-handling-I.html

你可能感兴趣的:(SQL,SERVER,数据库)