Created
June 10, 2025 01:21
-
-
Save rdmershon/819fa7f5a65c5905f99e808cc5bdd1d1 to your computer and use it in GitHub Desktop.
SQL I can't remember, relationships between two tables pt.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Foreign keys are used to establish relationships between tables. Typically, we use a primary key in one table and a foreign key in another table to create a one-to-one or a one-to-many relationship between those two tables. | |
| In a one-to-one relationship, one table serves as a parent table and the other table serves as a child table. With a foreign key constraint, a record must exist in the parent table before a related record can be added to the child table. In other words, a record in the child table must have a related record in the parent table. |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Foreign keys are referred to as FK when referring to the foreign key in the primary table. ex:
Employee
employee_id
name
email
department_id (FK)
Department
department_id
name