guide
guide8 min read

How to find duplicate tables in a warehouse: a step-by-step guide

Five steps from schema fingerprints to a safe retirement list

To find duplicate tables in a warehouse, fingerprint every table's column signature from the metadata views, group tables that share a signature, then confirm each candidate group by hashing row content (for example with Snowflake's HASH_AGG function). Metadata narrows thousands of tables to a short list, and the hash tells you whether two tables actually hold the same data. Usage and lineage then tell you which copy is safe to retire.

Key Takeaways

  • •Duplicate tables come in three kinds: exact copies (same schema, same rows), near copies (same rows, renamed or reordered columns) and drifted copies (same source, different freshness). Each needs a different test.
  • •Metadata is the cheap first pass. Column names, types and row counts from the information schema eliminate most non-duplicates without scanning any data.
  • •A content hash is the only reliable confirmation of identical rows. Compare an order-independent hash of both tables rather than eyeballing row counts.
  • •Never delete on a match alone. Check downstream lineage and recent query activity first, and retire by renaming or revoking access before you drop.
  • •Duplicates are a recurring problem, not a one-off cleanup. Rerun the detection on a schedule or hand it to an agent.

How to find duplicate tables in a warehouse: what counts as a duplicate

Before writing any SQL, decide which kind of duplicate you are hunting. A loose definition produces a long list of false positives and nobody trusts the output.

  • •Exact duplicates: identical column names, types and row content. Typical causes are a CREATE TABLE AS SELECT someone ran for a one-off analysis and never dropped, or a backup taken before a migration.
  • •Near duplicates: the same rows with renamed columns, a different column order or an extra audit column. These come from refactors where the old model was left running beside the new one.
  • •Drifted duplicates: two tables built from the same source by different jobs. They match today and diverge after the next schema change or late-arriving data.
  • •Semantic duplicates: different grain or different filters, but answering the same business question (two versions of daily_revenue). Hashing cannot find these, and they need a human or an agent reading the SQL definitions.

This guide covers the first three with SQL and touches the fourth in step 5. The examples use Snowflake and BigQuery syntax, but the method carries to any warehouse that exposes an information schema.

Step 1: Inventory every table and its size

Start with the metadata. In Snowflake, the ACCOUNT_USAGE TABLES view lists every table with its row count, size in bytes, creation time and owner. BigQuery exposes the same through INFORMATION_SCHEMA.TABLES. Pull the schema, table name, row count, bytes, created time and last altered time into one working table, excluding views and any system schemas.

Two tables with different row counts are not exact duplicates, so you can already discard those from the exact-match pass. Two tables with the same row count and similar byte size are your first candidates. Keep the near-duplicate pass separate, because renamed columns can still hold identical rows.

Step 2: Fingerprint the schema and group matches

Next, build a signature per table from its columns. Query the columns view, order columns by name, and concatenate column_name:data_type into one string, then hash it. Tables that share a schema hash and a row count go into the same candidate group. For near duplicates, sort the column names before hashing so that column order stops mattering, and compute a second signature using only the data types to catch renamed columns.

Treat the output as a ranked list. A group of two tables with identical schema and identical row count is high confidence. A group of six tables that share a generic schema (an id and a created_at, say) is usually coincidence, so push those down the list.

This step is pure metadata, so it costs almost nothing on most warehouses. That is why it comes before any scan of table data.

Step 3: Hash the rows to confirm

Now confirm each candidate group by comparing content. In Snowflake, SELECT HASH_AGG(*) FROM schema.table returns one value that is independent of row order, so two tables with the same value hold the same rows, with an extremely small collision risk (see the HASH_AGG documentation for the exact behavior and caveats). For near duplicates, hash an explicit column list in a shared order instead of *.

BigQuery has no direct equivalent function. A common pattern is BIT_XOR(FARM_FINGERPRINT(TO_JSON_STRING(t))) over the table alias, which is also order-independent. It is a pattern we use, not a built-in guarantee, so for tables where a false match would be costly, finish with an EXCEPT DISTINCT diff in both directions and confirm both return zero rows.

Hashing scans the full table, so run it only on the shortlisted groups and on a small warehouse. For very large tables, hash a deterministic sample first (for example every row whose primary key hash falls in one bucket). A sample mismatch rules a pair out cheaply, and only a sample match needs the full hash.

Step 4: Check lineage and usage before touching anything

A confirmed duplicate is not a deletable duplicate. Two questions decide what happens next: who reads each copy, and what is built on top of each copy.

For reads, query the access history. Snowflake's ACCESS_HISTORY view records which tables each query touched, so you can count distinct users and last-read date per table over the past 90 days. If one copy was queried yesterday by a dashboard service account and the other has not been read in a quarter, you know which one is canonical.

For dependencies, check views, downstream models and scheduled jobs that reference each copy. The question we hear most from teams at this point is the one in our own prompt list: "What's the blast radius if I drop this column?" The table-level version is the same, and you want an answer before the drop, not after the page.

This is the step where doing the work by hand gets slow, because the answers live in three places: query history, lineage and the catalog. Our Usage Intelligence Agent works from who-queried-what across the warehouse and scores tables hot or cold, which turns "What tables haven't been queried in 90 days?" into a single question from your terminal. We covered the broader cleanup workflow in our post on finding unused tables, and the Catalog Agent supplies ownership so you know who to ask before anything changes.

Step 5: Pick the canonical copy and retire the rest safely

For each confirmed group, choose the canonical table using four signals in this order: it is the one with downstream dependents, it is the one with recent readers, it has a named owner, and it sits in the schema your team treats as production. When two copies tie, prefer the one built by a version-controlled job over a hand-created one.

Then retire in stages rather than dropping:

  • •Day 0: tag the duplicate with a deprecation note and an owner, and notify the last readers.
  • •Day 1: revoke read access, or rename the table with a _deprecated suffix, so anything still depending on it fails loudly and recoverably.
  • •Day 14 to 30: if nothing complained, drop it. Warehouse time travel or fail-safe windows add a recovery margin, but do not rely on them as your plan.
  • •Afterward: point any views or models that referenced the duplicate at the canonical table and keep the group in a log, so the same copy is not recreated unnoticed.

For the semantic duplicates from the definitions above, read the SQL that builds each table. Two tables with different grain are not duplicates, but two daily_revenue tables with different filters usually point to a metric-definition problem rather than a storage one. That belongs in a governance review, not a drop script.

Run the detection from Claude Code or Cursor

Every Data Workers agent is an MCP server, so the same investigation can run inside Claude Code or Cursor instead of in a folder of one-off scripts. Details of the protocol are on the Model Context Protocol site. The OSS edition (dw-claw) is Apache 2.0, runs locally and is read-only by default, which suits this job: finding and ranking duplicates needs reads only, and the retirement steps stay in your hands unless you enable writes in Pro with approval workflows.

A realistic session asks "Which tables in analytics are exact copies of another table?" and gets back groups with schema match, content hash result, last reader and owner. Pair it with the cost question, "How much are we spending on Snowflake this month?", and each duplicate group gets a dollar figure for storage and refresh compute, which is usually what gets cleanup prioritized. We cover cost attribution in a separate post.

Common mistakes when hunting duplicate tables

  • •Comparing only row counts. Equal counts say nothing about content, and many tables share a count by chance.
  • •Hashing every table in the warehouse. Use metadata to shortlist first, then hash only the candidates.
  • •Treating clones as waste. Zero-copy clones in Snowflake share storage until they diverge, so a clone costs little. Check storage metrics before you count one as a saving.
  • •Dropping the older copy by default. The older table is often the one everything still reads from.
  • •Running the cleanup once. Without a schedule or an owner, duplicates return within a few quarters.

Frequently Asked Questions

How do I find duplicate tables in Snowflake? Pull table metadata from the account usage views, group tables by a hash of their column signature and row count, then confirm each group with HASH_AGG over the rows. Check ACCESS_HISTORY for readers before dropping anything.

Is comparing row counts enough to tell if two tables are duplicates? No. Matching row counts only mean two tables are worth comparing. Confirm with an order-independent content hash, or an EXCEPT diff in both directions that returns zero rows.

How do I find tables that hold the same data but have different column names? Hash a list of columns in a fixed order instead of selecting all columns, and match columns by data type and sample values rather than by name. Then verify the mapping with a row-level diff before you treat the pair as duplicates.

Is it safe to delete a duplicate table once the hashes match? Not yet. Check downstream views, models and scheduled jobs, look at recent query activity, and stage the retirement with a rename or access revoke before the drop.

Can an AI agent find duplicate tables for me? Yes, for the detection and ranking. An agent connected over MCP can run the metadata, hash and usage queries and return a ranked list with owners. We recommend keeping drops behind a human approval step.