How does BigQuery handle primary and foreign keys compared to an RDBMS that enforces them?

Quick Overview

Asks how BigQuery treats declared primary and foreign key constraints and how that differs from a relational database that enforces them on every write. Tests understanding of query optimizer behavior, data quality checks in a pipeline, and warehouse modeling choices.

How does BigQuery handle primary and foreign keys compared to an RDBMS that enforces them?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

How does BigQuery handle primary and foreign keys, and what are the implications compared to a traditional RDBMS that enforces these constraints? ```hint Declared versus checked Look at what happens at write time when a row breaks a declared key, and then ask which part of the system still reads the declaration. ``` ```hint Follow the assumption If some component trusts a key that the data does not satisfy, think about which query results could change without any error being raised. ``` ### What a Strong Answer Covers - Whether BigQuery accepts primary and foreign key declarations, in what form, and whether it checks them on load, streaming insert or DML. - What the declarations are used for once they exist, with a concrete query that benefits. - What goes wrong when a declared key does not hold in the data. - How responsibility for uniqueness and referential integrity moves to the pipeline, and how to test it. - How the lack of enforcement fits with typical warehouse modeling such as denormalized or nested tables. ### Follow-up Questions - How would you deduplicate a table fed by a streaming pipeline that can deliver the same event more than once? - Write a check that finds orphaned foreign key values. Where in the pipeline would you run it, and what should happen when it fails? - When would you choose not to declare a primary key in BigQuery even though the column is meant to be unique? - How do nested and repeated fields change the need for a foreign key between a parent table and its child rows?

Overview: Asks how BigQuery treats declared primary and foreign key constraints and how that differs from a relational database that enforces them on every write. Tests understanding of query optimizer behavior, data quality checks in a pipeline, and warehouse modeling choices.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

How does BigQuery handle primary and foreign keys, and what are the implications compared to a traditional RDBMS that enforces these constraints?

What a Strong Answer Covers Guidance

  • Whether BigQuery accepts primary and foreign key declarations, in what form, and whether it checks them on load, streaming insert or DML.
  • What the declarations are used for once they exist, with a concrete query that benefits.
  • What goes wrong when a declared key does not hold in the data.
  • How responsibility for uniqueness and referential integrity moves to the pipeline, and how to test it.
  • How the lack of enforcement fits with typical warehouse modeling such as denormalized or nested tables.

Follow-up Questions Guidance

  • How would you deduplicate a table fed by a streaming pipeline that can deliver the same event more than once?
  • Write a check that finds orphaned foreign key values. Where in the pipeline would you run it, and what should happen when it fails?
  • When would you choose not to declare a primary key in BigQuery even though the column is meant to be unique?
  • How do nested and repeated fields change the need for a foreign key between a parent table and its child rows?