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

preview_player
Показать описание
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).

#ForeignKeys #PrimaryKeys #RelationalDatabase #CockroachDB
Рекомендации по теме
Комментарии
Автор

Very well explained and clearly illustrated. And I mean it!

hristohristov
Автор

Thank you for such a comprehensive way of presenting the information!

xskftxm
Автор

Best lecture to clear key confusions arising from definitions.

msingh
Автор

Well explained, Impressive illustrated 🤝Good job

rira
Автор

Concise and comprehensive explanation! Thanks very much!

bradleyli
Автор

Thank you! I couldn't understand this concept from the Coursera course I'm taking. Your video effectively cleared my confusion!

purpledragon
Автор

it took me at least 30 minutes to find an understanding video. That doesn't have an overly thick uninteresting indian guy making 0 sense. And i finally found someone who explains it in under 10 minutes and is short, simple and awesome. Thank you very much

shukes
Автор

Is there a way to use this concept to avoid duplicating data across tables? For example - there is an Orders table and a MyOrders table. I'd like MyOrders table to automatically reference Orders without duplicating the data in it....

igorg.
Автор

Great but is it also possible that a column is both a primary key and foreign key in the same table

-.-_._--
Автор

So it's not possible to insert data only into a parent table without having an error?

senju