SSMS Tip Of The Day – Show Row Count

Today, when clicking around SSMS, I discovered this little helpful trick, that you probably already knew but here it comes anyway.

If you want to see the number of rows in a table you can always use

Select count(*) from TableName

but it has quite a nasty performance.

Another way to do it with much better performance

SELECT SUM(row_count) as NumberOfrows FROM sys.dm_db_partition_stats WHERE OBJECT_NAME(object_id) = TableName AND index_id < 2

Ultimately you might want to get the row count for all the tables of your database.

SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count AS NumberOfrows FROM sys.dm_db_partition_stats st WHERE index_id < 2 ORDER BY st.row_count DESC

But when it comes to SSMS there is an easy way, which calls the above query behind the scenes. In the Object Explorer Details, choose Tables right click on a column header and add row count and here you go…


Happy row counting !

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: