What is CUBE in SQL Server?
Ask by Anubhav Sharma
Updated 19 Apr 2026
In SQL Server, CUBE is used in
GROUP BYto generate all possible combinations of aggregations across multiple columns.Simple Meaning
Syntax
Example
Suppose you have sales data:
Query:
Output Explained
CUBE will generate:
Result:
Key Point
NULLmeans total (aggregation)Query Using CUBE
Understanding
(Region, Product)→ Normal grouping(Region, NULL)→ Total per Region(NULL, Product)→ Total per Product(NULL, NULL)→ Overall totalDifference from ROLLUP
When to Use
Use CUBE when you need:
One-Line Summary