Monday, January 21, 2013

Get All the TABLES with Number of Rows and Columns

SELECT OBJECT_NAME(D.object_id) As [TABLE NAME], 
  SUM(row_count) [ROWS COUNT] , 
  Count(C.Column_Id) [COLUMN COUNT]
FROM sys.dm_db_partition_stats As D Inner JOIN sys.objects As o
  On o.object_id = D.object_id And o.type = 'u'
  Inner Join sys.columns As C On C.object_id = D.object_id
WHERE [index_id] IN (0,1)
GROUP BY D.object_id

No comments:

Post a Comment