http://www.sqlservercentral.com/blogs/powersql-by-prashanth-jayaram/2013/04/11/powershell-and-sql-easy-and-different-ways-to-find-number-of-rows-of-all-tables-in-a-database/

Printed 2014/11/25 04:19PM

PowerShell and SQL – Easy and Different Ways to Find Number of Rows of all Tables in a database

By Prashanth Jayaram, 2013/04/11

SQL Example:

DECLARE @TableRowsCount table
(
Tablename varchar(50),
cnt int)

insert into @TableRowsCount
EXEC sp_MSforeachtable @command1=” select ‘?’,count(*) from ?”

select * from @TableRowsCount

PowerShell Example:

Load SQL PowerShell by typing “SQLPS” in PowerShell console

PS:\>SQLPS

Change Directory to the desired database

PS SQLSERVER:\ cd SQL\HQDB001\default\databases\DummyDBName\tables

PS SQLSERVER:\SQL\HQDB001\default\databases\Powersql\tables> dir |format-table  Name,Rowcount



Copyright © 2002-2014 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.