This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tsql:count_rows_in_every_table [2018/07/04 22:23]
tsql:count_rows_in_every_table [2020/02/13 20:43] (current)
Line 27: Line 27:
 </​code>​ </​code>​
 +===== Quick and (possibly) approximate =====
 +The ''​[rows]''​ field in ''​sys.partitions''​ provides an [[https://​docs.microsoft.com/​en-us/​sql/​relational-databases/​system-catalog-views/​sys-partitions-transact-sql|approximate number of rows in each partition]]. ​
 +<code tsql>​SELECT
 +  QUOTENAME(OBJECT_SCHEMA_NAME([object_id])) + '​.'​ + QUOTENAME(OBJECT_NAME([object_id]))
 +, SUM([rows])
 +FROM sys.partitions
 +WHERE index_id = 1
 +AND OBJECT_SCHEMA_NAME([object_id]) NOT IN ('​sys'​)
 +--AND [rows] > 0
 +GROUP BY [object_id]
 {{tag> tsql dynamic testing warehouse}} {{tag> tsql dynamic testing warehouse}}