All examples
sqlserver

UNPIVOT Survey Responses

A wide survey table flattened into one row per (response_id, question). Lineage shows every wide column collapsing into one source column.

The lineage

survey_widev_survey_long
survey_wide UNPIVOTs into v_survey_long.

The SQL

CREATE TABLE survey_wide (
  response_id INT PRIMARY KEY,
  q1 INT, q2 INT, q3 INT, q4 INT, q5 INT
);

CREATE VIEW v_survey_long AS
SELECT response_id, question, score
FROM survey_wide
UNPIVOT (
  score FOR question IN (q1, q2, q3, q4, q5)
) u;

What the lineage shows

  • v_survey_long.score is sourced from any of survey_wide.q1..q5.
  • v_survey_long.question carries the source column name as a value.
  • UNPIVOT collapses many sources into one logical lineage edge per source column.