Foreign Key
A column in one table that references the primary key of another table, establishing a link between them.
In Depth
A foreign key is a column or set of columns in a table that references the primary key of another table, creating a relationship between the two tables. Foreign keys enforce referential integrity—ensuring that a value in the foreign key column must exist in the referenced primary key column. This prevents orphaned records and maintains data consistency. Foreign key constraints can specify cascading actions: CASCADE (automatically delete/update related records), SET NULL (set foreign key to NULL), RESTRICT (prevent the operation), or NO ACTION. Understanding foreign key relationships is crucial for text-to-SQL systems to generate correct joins.
How AI for Database Helps
AI for Database maps all foreign key relationships in your schema, enabling it to automatically join the right tables when answering multi-table questions.
Related Terms
Primary Key
A column or set of columns that uniquely identifies each row in a database table.
Join
A SQL operation that combines rows from two or more tables based on a related column between them.
Relational Database
A database that organizes data into structured tables with rows and columns, linked by defined relationships.
Ready to try AI for Database?
Query your database in plain English. No SQL required. Start free today.