← all posts
> Aug 25, 2026
powershellsql-serversearch

Finding which table a value lives in

Using pkfind to locate which table and column a given value or name comes from.

You spot a value in a report — a customer number, an error string, an email address — and you need to know where it comes from. Which table, which column. In a database you know well that's a five-second answer. In one you don't, it's twenty minutes of clicking through Object Explorer.

pkfind

pkfind is grep for the database. Give it a word and a scope:

pkfind '[email protected]' -Table SalesLT.Customer

At table scope it searches both the column names and the row values. Every hit comes back with a schema-qualified table, the member it matched, and — for a value hit — occurrences, the number of rows holding that value.

To search wider, name a bigger scope. Names only — tables, columns, indexes, constraints, routine bodies — is a catalog read, so it's effectively instant however big the database:

pkfind ProductNumber

Scanning actual row values across the whole database is the expensive one, so it prices the job and asks first:

pkfind giraffe -InData
Confirm
Performing the operation "Scan 37 text column(s) across 11 table(s), about
3,735 row(s)" on target "AdventureWorksLT2025".

The hits are objects

Every hit has the same shape whatever it matched, so results pipe onward:

  • pkfind giraffe -Only Table | peek — look at what you found
  • pkfind giraffe -Only Column | Export-Csv .\hits.csv — save the list
  • pktab '*audit*' | pkfind 'user id' — search a curated subset

Matching is substring by default, and case- and accent-insensitive even on a CS_AS database. Whitespace splits the term into tokens that all have to appear, in any order, so pkfind 'product number' finds ProductNumber, product_number and PRODUCT_NUMBER with no camel-case parsing. A * makes it an explicit wildcard; -Exact matches the whole identifier.

One thing worth keeping straight: this answers "where does this word appear anywhere in the database?", not "show me the rows matching this". For the second one you want peek -Where. Different question, different command.

Source and install: github.com/jackneff/SqlPeek.