Database Relationships and Foreign Keys

microsoft enterprise consortium microsoft n.w
1 / 9
Embed
Share

Learn about implementing relationships between entities in a database, including the use of primary and foreign keys. Understand the importance of foreign keys in reducing data redundancy in a relational database system.

  • Database
  • Relationships
  • Foreign Keys
  • Data Model
  • Relational

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Microsoft Enterprise Consortium Microsoft Enterprise Consortium Microsoft Enterprise Consortium Database Fundamentals Data Model: Physical Design Part 2 Primary & Foreign Keys 1 Prepared by Jennifer Kreie, New Mexico State University Hosted by the University of Arkansas

  2. Microsoft Enterprise Consortium Microsoft Enterprise Consortium What you should already know You should know relational data model terminology. You should know the database terms that correspond to the data model terms. For example: attribute = column/field In the previous presentation, we started implementing a physical data model in a relational database. This presentation begins with how to implement the relationship between two entities. 2 Prepared by Jennifer Kreie, New Mexico State University Hosted by the University of Arkansas

  3. Microsoft Enterprise Consortium Microsoft Enterprise Consortium Database relationships How do we put a relationship between the CUSTOMER and REPAIR ORDER tables in the database? We put the primary key from one table into the related table. Which primary key goes into the other table? CUSTOMER REPAIR ORDER 3 Prepared by Jennifer Kreie, New Mexico State University Hosted by the University of Arkansas

  4. Microsoft Enterprise Consortium Microsoft Enterprise Consortium Foreign key Foreign key: A foreign key is a field in one table that corresponds to a primary key field in another table. We know which primary key to put in a related table because of the one side and the many side of the relationship. The rule: In a one-to-many relationship the many side gets the foreign key. One-to-many CUSTOMER REPAIR ORDER The REPAIR ORDER table gets the foreign key column. 4 Prepared by Jennifer Kreie, New Mexico State University Hosted by the University of Arkansas

  5. Microsoft Enterprise Consortium Microsoft Enterprise Consortium Foreign key: Building a relationship The primary key field from CUSTOMER, which is CUST_ID, has a corresponding column in the related REPAIR ORDER table. The foreign key field, called CUSTID column in the example shown here, holds data that links to related data in the CUSTOMER table. For repair order #1 (Ord_ID), the #4 in the CustID field, tells us that this work was done for Debbie Davies. CUSTOMER REPAIR ORDER 5 Prepared by Jennifer Kreie, New Mexico State University Hosted by the University of Arkansas

  6. Microsoft Enterprise Consortium Microsoft Enterprise Consortium Data redundancy Using the foreign key field to link related data is an essential element of relational database. It reduces data redundancy. Each relational database table stores data about a particular entity (a person, place, thing, or event). In the example below, there are 3 repair orders for Debbie Davies. However, we don t store her information (name, address, etc.) more than once. The foreign key value #4 links Debbie Davies information to each of her repair orders. 6 Prepared by Jennifer Kreie, New Mexico State University Hosted by the University of Arkansas

  7. Microsoft Enterprise Consortium Microsoft Enterprise Consortium Foreign key field name The foreign key field name can match the related primary key field name exactly. This is often done. However, as shown in the example here, it is not required that the names match. In fact, in one situation, which you ll see later, the names cannot match. It is required that the foreign key column be defined so that it contains the same data as in the related primary key column. The foreign key column is the same data type and field size as the primary key column. 7 Prepared by Jennifer Kreie, New Mexico State University Hosted by the University of Arkansas

  8. Microsoft Enterprise Consortium Microsoft Enterprise Consortium This presentation covered A relationship in the data model becomes the link between a primary key column in one table and its related foreign key column in another table. Storing data in separate tables, such as data about customer stored in CUSTOMER and repair work data in REPAIR ORDER, reduces data redundancy. 8 Prepared by Jennifer Kreie, New Mexico State University Hosted by the University of Arkansas

  9. Microsoft Enterprise Consortium Microsoft Enterprise Consortium Resources Microsoft Enterprise Consortium: http://enterprise.waltoncollege.uark.edu/mec.asp Microsoft Faculty Connection Faculty Resource Center http://www.facultyresourcecenter.com/ 9 Prepared by Jennifer Kreie, New Mexico State University Hosted by the University of Arkansas

More Related Content