SET NOCOUNT 的最佳位置在哪里?
对于在专用 SQL Server 上运行的大型数据库(数千个存储过程),最好在每个存储过程的顶部包含 SET NOCOUNT ON
,还是在服务器级别(属性 -> 连接 -> 无计数"复选框)?这听起来像是 DRY 原则(不要重复自己"),并且该选项应该只设置在一个地方.如果 SQL Server 还托管了其他数据库,那将反对在服务器级别设置它,因为其他应用程序可能依赖于它.SET NOCOUNT
的最佳位置在哪里?
For a large database (thousands of stored procedures) running on a dedicated SQL Server, is it better to include SET NOCOUNT ON
at the top of every stored procedure, or to set that option at the server level (Properties -> Connections -> "no count" checkbox)? It sounds like the DRY Principle ("Don't Repeat Yourself") applies, and the option should be set in just one place. If the SQL Server also hosted other databases, that would argue against setting it at the server level because other applications might depend on it. Where's the best place to SET NOCOUNT
?
推荐答案
将其设为服务器的默认设置(除历史原因外,将设为默认设置).我从一开始就对所有服务器执行此操作.有没有想过为什么它是 SET NOCOUNT ON 而不是 SET COUNT OFF?这是因为在 Sybase 时代,唯一的 UI 是 CLI;当查询可能没有结果时显示计数是很自然的,因此没有指示它已完成.
Make it the default for the server (which it would be except for historical reasons). I do this for all servers from the start. Ever wonder why it's SET NOCOUNT ON instead of SET COUNT OFF? It's because way way back in Sybase days the only UI was the CLI; and it was natural to show the count when a query might show no results, and therefore no indication it was complete.
相关文章