What is a foreign key in a database?

A foreign key is a column in one table that references the primary key of another table, creating a link between them. It enforces referential integrity, ensuring, for example, that every order row points to a customer that actually exists, and is how relational databases model relationships.

Foreign keys are how relational data connects. If an orders table has a customer_id that matches the customer_id primary key in a customers table, that column is a foreign key, and it tells the database (and any analyst) how the two tables relate.

They provide:

  • Relationships linking transactions to the entities they belong to.
  • Referential integrity blocking orphan records that reference something non-existent.
  • Join paths the roadmap for combining tables in a query.

In practice, foreign keys are not always declared explicitly; sometimes the relationship exists only by convention, or lives across two separate systems that never enforced it.

iDBQuery is designed for both cases. During schema introspection it detects declared foreign keys, and its semantic layer can infer likely join relationships even when they are not formally defined, or when the related data sits in a different database or spreadsheet. Ask a question that needs several tables joined and iDBQuery figures out the key relationships, writes the correct join, and cites each figure back to its source rows, so cross-table and cross-source analysis just works.

Updated 2026-06-22