/*BEGIN TRY
select row_count SegmentSize,row_count*count_big(*) RowsInSegment,count_big(*) SegmentCount
from sys.column_store_segments
group by row_count
	END TRY
	BEGIN CATCH
	select 1
	END CATCH
*/

	select  object_name(p.object_id) AS TABLE_NAME, 
	COUNT_BIG(distinct(column_id)) AS NUM_COL,
	Sum(Cast(s.row_count AS BIGINT)) / Count(DISTINCT( s.column_id )) AS NUM_ROWS,
	COUNT_BIG(distinct(p.partition_id)) as NUM_PARTITIONS,
	COUNT_BIG(*)/COUNT_BIG(distinct(column_id))  AS NUM_ROWGROUPS,
	COUNT_BIG(*)  AS NUM_SEGMENTS,
	AVG(Cast(s.row_count AS BIGINT)) as AVG_ROWCOUNT_PER_SEGMENT,
	MIN(Cast(s.row_count AS BIGINT)) as MIN_ROWCOUNT_PER_SEGMENT,
	MAX(Cast(s.row_count AS BIGINT)) as MAX_ROWCOUNT_PER_SEGMENT,
	SUM(Cast(s.on_disk_size AS BIGINT))/1024/1024 as TOTAL_SIZE_MB
from sys.column_store_segments s, 
	sys.partitions p
where s.partition_id = p.partition_id
group by p.object_id
order by object_name(p.object_id)
GO
