Skip to main content

What is a Foreign Key Constraint? Understanding Primary & Foreign Keys

In this short video we'll cover what foreign keys are, why they are important, how they differ from Primary Keys and how they function in a relational database. 00:00 Introduction 0:21 Example of Foreign Keys in a database 0:32 What is a Primary key? 1:19 What is a foreign key? 2:02 What do foreign keys do? 3:27 Review of Foreign Keys In this video, we are focusing on foreign keys that link one column in a table to one column (the primary key) in another table for the sake of simplicity. Your own use of a foreign key can be more complex: foreign keys can link to a compound (more than one column) in another table, and foreign keys do not have to link to another table's primary key. Just keep in mind that whatever your foreign key is referencing in the other table must have a unique constraint (this is why using a foreign key to reference another table's primary key is often a good idea, since we know that has a unique constraint by default). Next video: how to use foreign keys in SQL: More documentation on foreign keys: #ForeignKeys #PrimaryKeys #RelationalDatabase #CockroachDB