What is a Foreign Key Constraint? Understanding Primary & Foreign Keys
CockroachDB CockroachDB
9.98K subscribers
52,193 views
698

 Published On Jul 1, 2021

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:    • How to Create Tables with Foreign Key...  

More documentation on foreign keys: https://www.cockroachlabs.com/docs/st...

#ForeignKeys #PrimaryKeys #RelationalDatabase #CockroachDB

show more

Share/Embed