我們的品牌

Impact-Company-Logo-English Black-01-177x54

歡迎造訪施耐德電機全球網站

歡迎訪問我們的網站
		
我们今天能为您提供什么帮助?
Approximate Count in Microsoft SQL Server 2019

Issue
The SQL Count(distinct()) function provides the actual row count and may take a very long time to execute on a very large database table.

Product Line
Power Monitoring Expert 7.2.2
Power Monitoring Expert 8.2
Power Monitoring Expert 9.0
Power Monitoring Expert 2020
Power Monitoring Expert 2021
Power Monitoring Expert 2022
Power Monitoring Expert 2023
Power Monitoring Expert 2024

Environment

SQL Server 2012

SQL Server 2016

SQL Server 2019

SQL Server 2022

Cause
The Count(distinct()) function provides the actual row count.  This may take a considerable amount of time with tables containing millions or billions of rows.
This could consume a large amount of time while waiting for the result, if all you require is an approximate row count.

Resolution
*Warning: Irreparable database damage can occur. This procedure should only be performed by users familiar with SQL Server Management Studio.
Databases should be backed up prior to performing this procedure.*

SQL Server 2019 introduces the new function Approx_Count_Distinct to provide an approximate count of the rows. The APPROX_COUNT_DISTINCT function
does not return the actual number of rows with each distinct value, but instead returns an approximate count. The approximate count might be higher or lower
than the actual number. According to Microsoft's documentation, 97% of the time the APPROX_COUNT_DISTINCT function will be within the 2% of the actual value.

Below is an example of how to use this new function:

SELECT APPROX_COUNT_DISTINCT(MyColumn)
FROM [dbo].[MyTable];

The above command can be executed by logging into SQL Server Management Studio, entering the command inside a query window while
replacing both 'MyColumn' and 'MyTable' with the values of the column and table you are interested in.

施耐德電機Taiwan

探索更多
系列:
探索更多
系列:
  • 產品文檔
  • 軟體下載
  • 產品選型工具
  • 產品替代和替換
  • 幫助和聯絡中心
  • 尋找我們的辦公室
  • 取得報價
  • 施耐德電機社群
  • 人才招募
  • 公司簡介
  • 舉報不當行為
  • 無障礙
  • 新聞中心
  • 投資者
  • 專業洞察
  • 台灣施耐德電機學院
  • 綠色影響力落差調查
  • Schneider Go Green 2025
  • 隱私政策
  • Cookie通告
  • 使用條款
  • Change your cookie settings