SET NOCOUNT ON usage

前端 未结 17 1746
抹茶落季
抹茶落季 2020-11-22 05:55

Inspired by this question where there are differing views on SET NOCOUNT...

Should we use SET NOCOUNT ON for SQL Server? If not, why not?

17条回答
  •  心在旅途
    2020-11-22 06:20

    At the risk of making things more complicated, I encourage a slightly different rule to all those I see above:

    • Always set NOCOUNT ON at the top of a proc, before you do any work in the proc, but also always SET NOCOUNT OFF again, before returning any recordsets from the stored proc.

    So "generally keep nocount on, except when you are actually returning a resultset". I don't know any ways that this can break any client code, it means client code never needs to know anything about the proc internals, and it isn't particularly onerous.

提交回复
热议问题