🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Snowflake Data Lineage: Access History and Columns

đŸŸĸ Free Lesson

Snowflake Data Lineage

Snowflake Metadata

Lineage as a byproduct of queries

Snowflake does not maintain a separate lineage graph the way a catalogue tool does. Instead, every query's object access is recorded in ACCESS_HISTORY, with column-level detail for both the objects read and the objects written, and lineage is assembled by joining those records. The advantage of this approach is that lineage reflects what actually ran rather than what a pipeline definition claims should run; the cost is that the assembly is your job, and the raw records are verbose.

Two views carry almost everything. SNOWFLAKE.ACCOUNT_USAGE.ACCESS_HISTORY answers "which columns of which objects did this query read and write", with the column lists preserved as arrays of objects. SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY answers "what text did the query contain, who ran it, and when". Joined on query_id, they reconstruct both the structure and the intent of a transformation.

  • Column-level access is recorded for reads and writes, not just object-level.
  • Lineage is a join over history, so it is only as complete as your retention window.
  • Views, tasks, and streams appear as ordinary queries, which keeps lineage continuous across orchestration.

Prerequisites

  • !Snowflake query history familiarity
  • !JSON path notation

What You'll Learn

  • 1Query ACCESS_HISTORY for column-level reads and writes
  • 2Trace upstream sources and downstream consumers of a column
  • 3Assemble a dependency graph from access records
  • 4Supplement automated lineage with documented transformation intent

What ACCESS_HISTORY records

Each row in ACCESS_HISTORY corresponds to one query and carries three object arrays: direct_objects_accessed, objects_modified, and base_objects_accessed. The distinction between direct and base matters — a query against a view records the view as direct and the underlying tables as base, which is exactly the signal you need to follow lineage through a view layer rather than stopping at it.

-- Column-level reads for one table
SELECT
  q.query_id,
  q.query_text,
  q.user_name,
  q.role_name,
  q.start_time,
  obj.value:objectName::STRING      AS object_name,
  col.value:columnName::STRING      AS column_name
FROM snowflake.account_usage.access_history a
JOIN snowflake.account_usage.query_history q
  ON q.query_id = a.query_id
JOIN LATERAL FLATTEN(input => a.direct_objects_accessed) obj
JOIN LATERAL FLATTEN(input => obj.value:columns) col
WHERE obj.value:objectName::STRING = 'ANALYTICS.CORE.ORDERS'
  AND a.query_start_time >= DATEADD(day, -30, CURRENT_TIMESTAMP())
ORDER BY a.query_start_time DESC
LIMIT 100;

-- What this query wrote
SELECT
  obj.value:objectName::STRING AS modified_object,
  col.value:columnName::STRING AS modified_column
FROM snowflake.account_usage.access_history a
JOIN LATERAL FLATTEN(input => a.objects_modified) obj
JOIN LATERAL FLATTEN(input => obj.value:columns) col
WHERE a.query_id = '01af...';   -- a real query id from your account

-- Queries that touched a view, and the base tables behind it
SELECT
  a.query_id,
  d.value:objectName::STRING AS direct_object,
  b.value:objectName::STRING AS base_object
FROM snowflake.account_usage.access_history a
JOIN LATERAL FLATTEN(input => a.direct_objects_accessed) d
JOIN LATERAL FLATTEN(input => a.base_objects_accessed) b
WHERE d.value:objectName::STRING ILIKE '%CURATED.ORDERS%'
  AND a.query_start_time >= DATEADD(day, -7, CURRENT_TIMESTAMP());

Column lists are arrays, so queries that do not select specific columns — SELECT *, or writes that insert whole rows — record an empty or absent column array. That is a real limitation: lineage through a SELECT * view stops at the object boundary. The fix is operational rather than technical: ban SELECT * in curated objects, which most teams need to do anyway for schema-stability reasons.

Upstream: where did this column come from

The upstream question is the one asked before a data incident — "what fed this field?" — and it is answered by walking the base_objects_accessed array for every query that wrote the object in question.

-- Immediate upstream sources of a curated table
SELECT DISTINCT
  b.value:objectName::STRING AS source_object,
  col.value:columnName::STRING AS source_column,
  q.query_text
FROM snowflake.account_usage.access_history a
JOIN snowflake.account_usage.query_history q
  ON q.query_id = a.query_id
JOIN LATERAL FLATTEN(input => a.objects_modified) m
JOIN LATERAL FLATTEN(input => a.base_objects_accessed) b
LEFT JOIN LATERAL FLATTEN(input => b.value:columns) col
WHERE m.value:objectName::STRING = 'ANALYTICS.CURATED.ORDERS'
  AND a.query_start_time >= DATEADD(day, -14, CURRENT_TIMESTAMP());

-- Recursively one level further: sources of the sources
WITH upstream AS (
  SELECT DISTINCT b.value:objectName::STRING AS obj
  FROM snowflake.account_usage.access_history a
  JOIN LATERAL FLATTEN(input => a.objects_modified) m
  JOIN LATERAL FLATTEN(input => a.base_objects_accessed) b
  WHERE m.value:objectName::STRING = 'ANALYTICS.CURATED.ORDERS'
    AND a.query_start_time >= DATEADD(day, -14, CURRENT_TIMESTAMP())
)
SELECT DISTINCT
  u.obj AS curated_source,
  b2.value:objectName::STRING AS raw_source
FROM upstream u
JOIN snowflake.account_usage.access_history a2
JOIN LATERAL FLATTEN(input => a2.objects_modified) m2
JOIN LATERAL FLATTEN(input => a2.base_objects_accessed) b2
WHERE m2.value:objectName::STRING = u.obj
  AND a2.query_start_time >= DATEADD(day, -14, CURRENT_TIMESTAMP());

Two- or three-level walks like this are usually enough to answer an incident question, because most curated objects are one or two hops from raw ingestion. For a full graph you want to persist the edges rather than recompute them, which is the dependency-graph section below.

A useful diagnostic while walking upstream is to separate ingestion writes from transformation writes. Ingestion jobs write raw tables from stages and appear in history with a distinctive shape — a COPY INTO or a Snowpipe call reading from an @stage path — while transformations read curated tables and write other curated tables. Distinguishing them tells you whether a surprising upstream edge is a genuine data flow or an artifact of a maintenance job that briefly rewrote a table, such as a backfill or a deduplication script. Filtering by query_type and by the presence of a stage path in query_text is usually enough to make that distinction, and it keeps incident timelines honest.

Downstream: what breaks if this column changes

Impact analysis is the more valuable direction and the easier one to run, because it is a direct filter over the objects a query read.

-- Every object that read this column in the last quarter
SELECT DISTINCT
  obj.value:objectName::STRING AS consumer_object,
  col.value:columnName::STRING AS column_used,
  COUNT(*) AS query_count,
  COUNT(DISTINCT q.user_name) AS distinct_users
FROM snowflake.account_usage.access_history a
JOIN snowflake.account_usage.query_history q
  ON q.query_id = a.query_id
JOIN LATERAL FLATTEN(input => a.direct_objects_accessed) obj
JOIN LATERAL FLATTEN(input => obj.value:columns) col
WHERE obj.value:objectName::STRING = 'ANALYTICS.CORE.ORDERS'
  AND col.value:columnName::STRING = 'CUSTOMER_ID'
  AND a.query_start_time >= DATEADD(day, -90, CURRENT_TIMESTAMP())
GROUP BY 1, 2
ORDER BY query_count DESC;

-- Which dashboards and users depend on a table being renamed?
SELECT
  q.user_name,
  q.role_name,
  COUNT(*) AS queries,
  MAX(q.start_time) AS last_used
FROM snowflake.account_usage.query_history q
WHERE q.query_text ILIKE '%ANALYTICS.CORE.ORDERS%'
  AND q.start_time >= DATEADD(day, -90, CURRENT_TIMESTAMP())
GROUP BY 1, 2
ORDER BY queries DESC;

Running the second query before a rename turns a potentially disruptive change into a conversation with a known list of people. The query_text ILIKE pattern is deliberately broad — it catches mentions inside comments and half-rewritten queries — so treat its results as a candidate list to confirm rather than a precise dependency set.

Assembling a dependency graph

For a mesh or a large warehouse, ad-hoc walks are not enough; you want a persistent edge table that the rest of the organisation can query. Building it from access history on a schedule is straightforward, and the table itself becomes the source for catalogues and impact dashboards.

-- Persisted lineage edges
CREATE OR REPLACE TABLE meta.lineage_edges (
  source_object STRING,
  target_object STRING,
  source_column STRING,
  target_column STRING,
  observed_at   TIMESTAMP_NTZ,
  query_id      STRING
);

-- Daily incremental edge load
INSERT INTO meta.lineage_edges
SELECT DISTINCT
  b.value:objectName::STRING AS source_object,
  m.value:objectName::STRING AS target_object,
  bcol.value:columnName::STRING AS source_column,
  mcol.value:columnName::STRING AS target_column,
  a.query_start_time,
  a.query_id
FROM snowflake.account_usage.access_history a
JOIN LATERAL FLATTEN(input => a.objects_modified) m
LEFT JOIN LATERAL FLATTEN(input => m.value:columns) mcol
JOIN LATERAL FLATTEN(input => a.base_objects_accessed) b
LEFT JOIN LATERAL FLATTEN(input => b.value:columns) bcol
WHERE a.query_start_time >= DATEADD(day, -1, CURRENT_TIMESTAMP())
  AND m.value:objectName::STRING ILIKE 'ANALYTICS.%';

-- Column-level graph for one column
WITH RECURSIVE chain AS (
  SELECT source_object, source_column, target_object, target_column, 1 AS depth
  FROM meta.lineage_edges
  WHERE source_column = 'CUSTOMER_ID'
  UNION ALL
  SELECT e.source_object, e.source_column, e.target_object, e.target_column, c.depth + 1
  FROM meta.lineage_edges e
  JOIN chain c ON e.source_object = c.target_object
  WHERE c.depth < 8
)
SELECT * FROM chain ORDER BY depth, target_object;

-- Objects with the most dependencies: the riskiest to change
SELECT
  target_object,
  COUNT(DISTINCT source_object) AS upstream_count,
  COUNT(DISTINCT source_column) AS upstream_columns
FROM meta.lineage_edges
GROUP BY 1
ORDER BY upstream_count DESC
LIMIT 20;

The recursive CTE is bounded deliberately. Unbounded recursion over a graph with cycles — two tables that each feed the other through a reconciliation step — will not terminate on its own, so a depth cap is a correctness requirement, not an optimisation.

Documenting what SQL cannot express

Access history tells you that a query read a column; it cannot tell you why the transformation exists, what business rule it implements, or which of two conflicting sources is authoritative. Those facts live in text, and the teams that manage lineage well put that text next to the objects rather than in a wiki nobody opens.

-- Attach intent to the object itself
CREATE OR REPLACE TABLE meta.transformation_docs AS
SELECT * FROM VALUES
  ('ANALYTICS.CURATED.ORDERS',
   'Deduplicated by order_id, keeping the latest updated_at. Amounts are gross of tax; join tax separately from ledger.tax_lines. Owner: finance-data.'),
  ('ANALYTICS.CORE.CUSTOMERS',
   'One row per customer_id. Email is the business key for CRM matching; customer_id is the warehouse key. Never join on email alone.',
   ),
  ('ANALYTICS.MARTS.REVENUE_DAILY',
   'Daily revenue net of refunds, recognised on order date not payment date. Excludes internal test accounts flagged in customers.is_internal.')
AS t(object_name, documentation);

-- Surface docs next to lineage
SELECT
  e.target_object,
  d.documentation,
  e.upstream_count
FROM (
  SELECT target_object, COUNT(DISTINCT source_object) AS upstream_count
  FROM meta.lineage_edges GROUP BY 1
) e
LEFT JOIN meta.transformation_docs d
  ON d.object_name = e.target_object;

-- Where is documentation missing?
SELECT e.target_object
FROM (
  SELECT DISTINCT target_object FROM meta.lineage_edges
) e
LEFT JOIN meta.transformation_docs d ON d.object_name = e.target_object
WHERE d.object_name IS NULL;

That last query is the one that drives improvement. It names the objects carrying the most dependencies and no documentation, which is the exact set where an undocumented rule will cause the most damage during the next incident.

Putting lineage in front of analysts

A lineage graph nobody can query is an artefact, not a capability. The lowest-effort high-impact pattern is to expose the edge table and the documentation as ordinary views, so anyone with warehouse access can answer their own impact questions without knowing SQL over ACCESS_HISTORY.

CREATE OR REPLACE VIEW meta.v_column_lineage AS
SELECT
  source_object,
  source_column,
  target_object,
  target_column,
  MAX(observed_at) AS last_observed
FROM meta.lineage_edges
GROUP BY 1, 2, 3, 4;

CREATE OR REPLACE VIEW meta.v_impact AS
SELECT
  l.source_object,
  l.source_column,
  l.target_object,
  l.target_column,
  d.documentation AS target_documentation
FROM meta.lineage_edges l
LEFT JOIN meta.transformation_docs d ON d.object_name = l.target_object;

-- Grant read broadly; lineage is only useful if it is discoverable
GRANT SELECT ON VIEW meta.v_column_lineage TO ROLE PUBLIC;
GRANT SELECT ON VIEW meta.v_impact TO ROLE PUBLIC;

A second pattern worth building is a pre-change check: before altering or dropping a column, run the impact view and paste the consumer list into the change ticket. Making that a one-command step is what turns lineage from an interesting audit tool into part of the development workflow.

One caution about permissions: ACCOUNT_USAGE views require elevated access, so the account that runs the daily edge load needs a role granted to read them, while the analysts who query the assembled views need only USAGE on the metadata schema and SELECT on the views. Separating those two privileges keeps the sensitive raw history — which includes every query text and every user name in the account — behind a service role, while the derived graph stays broadly readable. That separation is also what lets you redact or generalise anything sensitive in the edge table before it is exposed.

Mistakes that make lineage untrustworthy

Common Mistakes

Trusting object-level lineage when column-level is available

Fix: Always flatten the columns array; object-level records hide which fields actually moved.

Expecting lineage through SELECT * views

Fix: Empty column arrays stop the walk; ban SELECT * in curated layers so lineage stays continuous.

Recomputing the full graph on every question

Fix: Persist edges incrementally so impact queries are milliseconds instead of full account scans.

Running recursive lineage without a depth bound

Fix: Cycles exist in real warehouses; cap depth or track visited nodes to guarantee termination.

Relying on lineage older than the retention window

Fix: Access history is bounded by retention; archive edges into your own table before they age out.

Leaving documentation in a wiki separate from the objects

Fix: Store intent in a table joined to lineage so it is visible exactly where the question is asked.

Treating query_text ILIKE matches as precise dependencies

Fix: They include comments and dead code; confirm candidates before acting on them.

Never measuring documentation coverage

Fix: Query for undocumented high-dependency objects and treat the result as a backlog.

Practices that keep lineage useful

Best Practices

  • Persist lineage edges daily so impact analysis does not depend on live account history.
  • Keep column-level records; object-level lineage answers only half the question.
  • Ban SELECT * in curated objects to preserve lineage continuity through views.
  • Bound recursive graph walks and document the bound.
  • Store transformation intent in a table joined to the lineage views.
  • Expose lineage as ordinary views granted to PUBLIC so analysts self-serve.
  • Run the impact query as a required step before any column rename or drop.
  • Review the undocumented high-dependency list each quarter and fill the gaps.

Key takeaways

Key Takeaways

  • Snowflake lineage is assembled from ACCESS_HISTORY and QUERY_HISTORY rather than maintained separately.
  • Direct versus base objects is the distinction that lets walks continue through views to real tables.
  • Downstream impact analysis is a single flatten-and-filter query, and it is the most valuable direction.
  • Persisting edges into your own table converts ad-hoc walks into a queryable graph.
  • Recursive walks need a depth bound because real warehouses contain cycles.
  • Automated lineage cannot express business intent; document intent next to the objects and join it in.
  • Lineage that is not exposed as a view will not be used when an incident starts.

Where to go next

  • Access History — the underlying view these patterns query.
  • Query History — performance and text search over executed queries.
  • Governance — how lineage evidence supports classification and compliance.
  • Data Quality — testing the transformations lineage discovers.
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-13

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Snowflake Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement