Skip to main content
Library homepage
 
Loading table of contents menu...
Engineering LibreTexts

5.1: Relationships and the Relationships Tool

  • Page ID
    23882
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The Relationships Tool is used to define relationships between tables based on common fields. Relationships defined using the Relationships Tool are important as they help ensure integrity of data and they provide us with default join criteria for queries involving more than one table. In this section we will use the University and the Library databases in our examples.

    Consider the University database we have been using that contains a Department table and a Course table. These two tables have the deptCode field in common:

    In the Department table, deptCode is the primary key and is used to identify a specific department.

    In the Course table, the deptCode field is a part of the primary key and indicates the department to which the course belongs.

    To ensure that a row in Course is related to an existing row in Department we can use the Relationships Tool to define a relationship between these two tables based on this common field. Using a diagram we can illustrate this connection between these two tables:

    Showing a relationship between two tables.
    Figure \(\PageIndex{1}\): Showing a relationship between two tables.

    In this situation we say that deptCode in Course is a foreign key referencing the deptCode field in Department.

    Now, consider the Library database:

    The Loan table has a callNo field and so does the Book table; the callNo field identifies a specific book.

    The Loan table has an id field and so does the Member table; the id field identifies an individual member.

    In the Library database we can establish a relationship between Loan and Book based on the callNo field, and a second relationship between Loan and Member based on the id field. Using a diagram we can illustrate these two relationships:

    Showing relationships involving three tables.
    Figure \(\PageIndex{2}\): Showing relationships involving three tables.

    The Loan table has two foreign keys, callNo and id:

    The callNo field in Loan references the primary key (callNo) in Book.

    The id field in Loan references the primary key (id) in Member.


    This page titled 5.1: Relationships and the Relationships Tool is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Ron McFadyen.

    • Was this article helpful?