Simple way to generate count of rows of all tables in MSSQL Database

If you intend to get the count of rows of all tables in MSDB database below is the query.

 Use msdb

Go

Select 'Select count(*) From' +name from sys.sysobjects

Where type = 'U' 

once this query is executed in MSSQL query analyser you will see below result.

Easy_Select_query_result_Untitled

please refer for more details – http://blogs.msdn.com/b/chrissk/archive/2010/06/27/example-code-executing-tsql-for-each-table-in-a-database.aspx

You can add conditions to the query as shown below –


Use msdb

Go

Select 'Select count(*) From ' +name from sys.sysobjects

Where type = 'U' and name like '%sysm%'

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s