Labels

Tuesday, 8 October 2019

Script to fine row count of each table available in a database

The below script will useful to find row count of tables along with creation date.

SELECT SCHEMA_NAME(st.schema_id) AS [SchemaName]
 ,[Tables].name AS [TableName]
 ,st.create_date
 ,SUM([Partitions].[rows]) AS [TotalRowCount]
FROM sys.tables AS [Tables]
INNER JOIN sys.partitions AS [Partitions] ON [Tables].[object_id] = [Partitions].[object_id]
 AND [Partitions].index_id IN (
  0
  ,1
  )
INNER JOIN sys.tables st ON st.name = tables.name
-- WHERE [Tables].name = N'name of the table'
GROUP BY SCHEMA_NAME(st.schema_id)
 ,[Tables].name
 ,st.create_date
ORDER BY 4 DESC

No comments:

Post a Comment