The COUNT_BIG is an aggregate function in SQL server which returns the number of items within a group. This function works like COUNT function but the only difference is the data type of its return values. The COUNT_BIG function return type is bigint, COUNT function return type is int.
Syntax
COUNT_BIG ( { [ [ ALL | DISTINCT ] expression ] | * } )
ALL - It is the default in COUNT_BIG function. This applies the aggregate function to all values.
DISTINCT - This returns the number of unique nonnull values.
Expression - It is an expression of any type but does not support aggregate functions or subqueries.
* - This denotes that all the rows should be counted, including the duplicate rows and null values and returns the total number of rows in a statement.
Let's look into an example,
SELECT COUNT_BIG(*) AS "Work Order Count" FROM [AdventureWorks2019].[Production].[WorkOrder]
Result:
ALL
SELECT COUNT_BIG(ALL WorkOrderID) AS "Work Order Count" FROM [AdventureWorks2019].[Production].[WorkOrder]
Result:
DISTINCT
SELECT COUNT_BIG(DISTINCT ProductID) AS "Product Count" FROM [AdventureWorks2019].[Production].[WorkOrder]
Result:
Comments