Blog Post

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

,

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

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating