create table #RowCount (TableName sysname, NoOfRows int)
exec sp_MSforeachtable
'insert into #RowCount select ''?'', count(*) from ?'
select * from #RowCount
order by NoOfRows desc
drop table #RowCount
go
-- OR
-- OR
-- ACCURATE method - it takes longer - QUICK SYNTAX
-- SQL Server count all rows in all tables - sql server rowcount all tables
DECLARE @CountStats TABLE(SchemaName SYSNAME,
TableName SYSNAME,
RowsCount INT )
INSERT @CountStats
EXEC sp_msForEachTable
'SELECT PARSENAME(''?'', 2), PARSENAME(''?'', 1), COUNT(*) FROM ?'
SELECT *
FROM @CountStats
ORDER BY RowsCount DESC
No comments:
Post a Comment