Latest Post

Sunday, 11 December 2016

How to Count total Row with table in SQL Server database

Total Row Count in SQL Server database

Following is query that shows number of rows count with each table name  in a database.

SELECT '[' + SCHEMA_NAME(t.SCHEMA_ID) + '].[' + t.NAME + ']' AS Table_Full_Name
,SCHEMA_NAME(t.SCHEMA_ID) AS SCHEMA_NAME
,t.name AS Table_Name
,i.ROWS
FROM SYS.TABLES AS t 
INNER JOIN SYS.SYSINDEXES AS i 
ON t.OBJECT_ID = i.id AND i.INDID < 2 ORDER BY i.ROWS DESC

Output:-


Table_Full_Name SCHEMA_NAME Table_Name ROWS
[dbo].[EmployeeActionLogs] dbo EmployeeActionLogs 26
[dbo].[Employee] dbo Employee 13
[dbo].[Salary] dbo Salary 6
[dbo].[Account] dbo Account 4
[dbo].[Students] dbo Students 2

Government Jobs