SET NOCOUNT 的最佳位置在哪里?

时间:2023-02-22
本文介绍了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.

这篇关于SET NOCOUNT 的最佳位置在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:SQL 条件排序依据 下一篇:从 csv 字符串进行 sql 搜索

相关文章

最新文章