From the course: Database Foundations: Data Structures
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Self-referencing relationships
From the course: Database Foundations: Data Structures
Self-referencing relationships
- [Narrator] Relationships are almost always made between two different data tables. But it is possible for a column in a table to relate to another column in the same table. This is called a self-referencing relationship. A self-reference also known as a self-join or a recursive relationship follows all of the same rules as the relationships created between two tables. They can be one-to-one, one-to-many or many-to-many. The same unique constraints still apply and will dictate the type of relationship made. The only difference is that both columns are in the same table instead of two different tables, which sets up a hierarchy that can loop back on itself. So where might a self-reference be useful? They're used to model hierarchies within the same class. So for instance consider this table of employees. Each employee has an ID and the table also stores the ID of the employee's direct supervisor. If you mentally connect to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
One-to-many relationships2m 13s
-
(Locked)
One-to-one relationships1m 27s
-
(Locked)
Many-to-many relationships2m 14s
-
(Locked)
Self-referencing relationships1m 56s
-
(Locked)
Cascade updates and deletes4m 35s
-
(Locked)
Challenge: Link tables with keys1m 8s
-
(Locked)
Solution: Link tables with keys6m 23s
-
(Locked)
-
-
-