How to Get Rowcount of Every Table in SSMS? – Interview Question of the Week #288

Question: Can I list each table’s row count in SSMS without running COUNT(*) against every table? Yes. Select the database’s Tables folder, open Object Explorer Details with F7, and enable its Row Count column.

Separate groups of seedpods are visible together in a compartmented organizer

After my video about a quick table row count, readers asked how to view all the tables together. This is the SSMS shortcut I showed them. It is much less clicking than opening every table’s Properties window.

The three steps

  1. In Object Explorer, select the Tables folder of the intended database.
  2. Press F7, or use View, Object Explorer Details.
  3. Right-click a column header in that details pane and check Row Count. Sort that column if you want the largest counts first.
Original SSMS View menu shows Object Explorer Details F7
The menu alternative to F7.
Original column header menu has Row Count checked
Right-click the column header, not a table’s context menu.
Original WideWorldImporters table names schemas and row counts
The original table list. Two nonoverlapping native strips retain Name, Schema and Row Count; unrelated columns are omitted without changing the displayed values.

Use the count for the right question

Refresh the pane when you need current metadata, and check whether a filter is hiding tables. For a quick inventory, metadata counts are useful. Don’t assume this UI view is an exact transactionally consistent count of rows satisfying an application predicate.

The equivalent kind of metadata inventory can be scripted. The following sums only heap or clustered-index partitions so nonclustered indexes don’t multiply the count:

-- Run in the database you want to inventory.
SELECT SCHEMA_NAME(t.schema_id) AS schema_name, t.name AS table_name,
       SUM(p.row_count) AS approximate_rows
FROM sys.tables AS t
JOIN sys.dm_db_partition_stats AS p ON p.object_id = t.object_id
WHERE p.index_id IN (0, 1)
GROUP BY t.schema_id, t.name
ORDER BY schema_name, table_name;

row_count in this DMV is explicitly approximate. On SQL Server 2022 and later, its documented permissions are VIEW DATABASE PERFORMANCE STATE and VIEW SECURITY DEFINITION. Earlier versions use VIEW DATABASE STATE and VIEW DEFINITION.

For a single table, right-click it, select Properties and look at Storage. The original screenshot shows Orders with 73,595 rows:

Original Orders table Storage properties show Row count73595
One-table Properties view, cropped to the relevant controls.

I avoid an unnecessary full COUNT(*) merely to browse table sizes. If you need an exact count for a report or a WHERE predicate, use COUNT_BIG with the required query and isolation semantics. Metadata isn’t a substitute for that answer.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Server, SQL Server Management Studio, SQL Table Operation
Previous Post
What is Full Outer Join With Exclusion? – Interview Question of the Week #286
Next Post
Do MAX Function Scan Table? – Interview Question of the Week #289

Related Posts

1 Comment. Leave new

  • Thanks for sharing this impressive blog. I really appreciate the work you have done, you explained everything in such an amazing and simple way. I look forward to revisiting your site.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.