Database Relationships Objective 5.01 Understand database tables used in business
Making Friends with Relations Relationships  link data from individual tables to increase the usefulness of the database. ...
Relationships <ul><li>Table relationships increase the power of the database by allowing data to be stored separately, but...
Relationship Example <ul><li>A music store database contains three tables.  An Inventory table is linked by artist to a Ro...
Keys to the Relationship <ul><li>A primary key  unlocks the relationship potential of a table by creating a unique link be...
Primary and Foreign Keys <ul><li>When tables relate, the primary key of one table becomes a  foreign key  of the other tab...
Referential Integrity <ul><li>Referential integrity  protects related data that is stored in multiple tables.  </li></ul><...
What does a relationship look like? One record in the Student Table is related to one record in the Participation Table Re...
Setting up a Relationship <ul><li>Add one table’s primary key to a like field with the same properties in another table </...
One-to-One <ul><ul><li>Only one matching record between two tables </li></ul></ul><ul><ul><li>This relationship is the lea...
One-to-Many <ul><li>Most common type of relationship </li></ul><ul><li>One record in Table A links to multiple records in ...
Many-to-Many <ul><li>Multiple records in Table A are linked to multiple records in Table B </li></ul><ul><ul><li>For examp...
Function of the Junction Table <ul><li>A junction table is used with many to many relationships to join primary key fields...
 
Upcoming SlideShare
Loading in …5
×

Database Relationships

891 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
891
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Database Relationships

    1. 1. Database Relationships Objective 5.01 Understand database tables used in business
    2. 2. Making Friends with Relations Relationships link data from individual tables to increase the usefulness of the database. <ul><li>One of the great benefits of working with databases is the ability to store huge quantities of information. One company’s database may contain many tables of related information. </li></ul><ul><li>When the information between tables is linked, it is called a relationship. </li></ul>
    3. 3. Relationships <ul><li>Table relationships increase the power of the database by allowing data to be stored separately, but managed and retrieved collectively. </li></ul>
    4. 4. Relationship Example <ul><li>A music store database contains three tables. An Inventory table is linked by artist to a Royalty table which contains the artist’s contact information and royalty percentages </li></ul><ul><li>The Inventory table is also linked to a Sales table by salesperson ID numbers, which contains employee information and commission rates </li></ul><ul><li>Once a purchase is made, the inventory is adjusted in one table and the artist’s royalties and employee’s commissions are calculated from the information in the other tables </li></ul>What are the advantages of this system? Are there disadvantages?
    5. 5. Keys to the Relationship <ul><li>A primary key unlocks the relationship potential of a table by creating a unique link between tables </li></ul><ul><li>The related field between the two tables must be of the same data type and size </li></ul><ul><li>A join line represents the relationship between tables graphically </li></ul>
    6. 6. Primary and Foreign Keys <ul><li>When tables relate, the primary key of one table becomes a foreign key of the other table </li></ul><ul><li>For example, in the two tables on the right, </li></ul><ul><ul><li>Employee ID appears in the Employees Table as a primary key… </li></ul></ul><ul><ul><li>… and in the Orders Table as a foreign key </li></ul></ul>
    7. 7. Referential Integrity <ul><li>Referential integrity protects related data that is stored in multiple tables. </li></ul><ul><li>It would prevent a customer in a customers table from being deleted if the customer’s ID also appears in the order table </li></ul>
    8. 8. What does a relationship look like? One record in the Student Table is related to one record in the Participation Table Relationship established between two tables
    9. 9. Setting up a Relationship <ul><li>Add one table’s primary key to a like field with the same properties in another table </li></ul><ul><li>In order to decide which table’s primary key to use you must first determine the nature (type) of the relationship </li></ul><ul><li>There are 3 types of relationships </li></ul>
    10. 10. One-to-One <ul><ul><li>Only one matching record between two tables </li></ul></ul><ul><ul><li>This relationship is the least common because it is not a very efficient use of tables </li></ul></ul>
    11. 11. One-to-Many <ul><li>Most common type of relationship </li></ul><ul><li>One record in Table A links to multiple records in Table B </li></ul><ul><ul><li>For example: A list of suppliers for the music store is contained in Table A. It is linked by the supplier ID field to Table B which contains all of the products used by the music store. </li></ul></ul><ul><ul><li>When Table B is searched for a specific product (record), such as a CD carrying case, the manager can view the supplier’s contact information, which is stored in Table A. </li></ul></ul>
    12. 12. Many-to-Many <ul><li>Multiple records in Table A are linked to multiple records in Table B </li></ul><ul><ul><li>For example: In the music store database, Table A contains customer information and Table B contains CD inventory. A record for Bob from Table A may be linked to several records of CDs in Table B by linking the Customer ID fields. If Table B contains the CD inventory, a record for a particular CD can be linked to several customers in Table A. </li></ul></ul>
    13. 13. Function of the Junction Table <ul><li>A junction table is used with many to many relationships to join primary key fields of multiple tables </li></ul><ul><li>For example, in a Music Store database, the primary key fields of the Orders, Musicians, Inventory, and Prices tables are all contained in a separate table, which acts like a hub for the tables of the database </li></ul>

    ×