Taking inventory of an unfamiliar database
How I get the lay of an unfamiliar SQL Server database — tables, row counts, and sizes — in one command.
Someone hands you a database you've never seen. Before you can answer any real question about it, you need the lay of the land: what tables are in there, how big they are, how many rows. This is the part I got tired of doing by hand, so it's the first thing SqlPeek does.
One command, no arguments
pkon -s .\SQLEXPRESS -d AdventureWorksLT2025
pktab
Schema Name Type Rows SizeMB
------ ---- ---- ---- ------
dbo BuildVersion table 1 0.07
dbo ErrorLog table 0 0.00
SalesLT Address table 450 0.33
SalesLT Customer table 847 0.49
SalesLT Product table 295 0.91
SalesLT ProductCategory table 41 0.05
SalesLT SalesOrderDetail table 542 0.13
SalesLT SalesOrderHeader table 32 0.06
Row counts come from sys.dm_db_partition_stats in one set-based pass — never a COUNT(*) per table — so it stays quick on a database with thousands of them, and it reads none of the actual data.
Narrow it with a wildcard when the list is long:
pktab '*order*'
Zooming in
Once a table looks worth a closer look:
| Command | What you get |
|---|---|
pkcol SalesLT.Customer |
its columns, in order, with types and nullability |
pkshape SalesLT.Customer |
row count by column count, metadata only, no data read |
pkdbsum |
table and view counts, total rows, total size, largest table |
pkdbsum is the whole-database version of the same question:
Database Tables Views TotalRows TotalMB LargestTable
-------- ------ ----- --------- ------- ------------
AdventureWorksLT2025 12 4 4277 2.56 Product
None of this replaces opening the database in SSMS and reading the schema properly. It's the five minutes before that, when you just want to know whether you're looking at a hundred rows or a hundred million. Then peek SalesLT.Customer -Top 20 to actually look at some.
With the session connected, peek SalesLT.<Tab> completes real table names from the live catalog, so the next step is mostly a guess and the Tab key.
Source and install: github.com/jackneff/SqlPeek.