1 / 14

Database Relationships

Database Relationships. Relationships. 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. When the information between tables is linked, it is called a relationship.

cheria
Download Presentation

Database Relationships

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Database Relationships

  2. Relationships • 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. • When the information between tables is linked, it is called a relationship. Relationships link data from individual tables to increase the usefulness of the database. 5.01 Understand database tables used in business

  3. Relationships • Table relationships increase the power of the database by allowing data to be stored separately, but managed and retrieved collectively.

  4. Relationship Example What are the advantages of this system? Are there disadvantages? • 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 • The Inventory table is also linked to a Sales table by salesperson ID numbers, which contains employee information and commission rates • 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

  5. Keys to the Relationship • A primary keyunlocks the relationship potential of a table by creating a unique link between tables • The related field between the two tables must be of the same data type and size • A join line represents the relationship between tables graphically

  6. Primary and Foreign Keys • When tables relate, the primary key of one table becomes a foreign key of the other table • For example, in the two tables on the right, • Employee ID appears in the Employees Table as a primary key… • …and in the Orders Table as a foreign key • Foreign key – when tables are linked by the primary key, the related field in the second table is known as the foreign key

  7. Referential Integrity • Referential integrity protects related data that is stored in multiple tables. • It would prevent a customer in a customers table from being deleted if the customer’s ID also appears in the order table

  8. Example • Referential integrity would prevent two cars from being assigned to the same driver or two cars from being assigned the same ID number. It would also prevent a driver from being deleted from a table if the driver is assigned to a car.

  9. Relationship established between two tables One record in the Student Table is related to one record in the Participation Table What does a relationship look like?

  10. Setting up a Relationship • Add one table’s primary key to a like field with the same properties in another table • In order to decide which table’s primary key to use you must first determine the nature (type) of the relationship • There are 3 types of relationships

  11. One-to-One • Only one matching record between two tables • This relationship is the least common because it is not a very efficient use of tables

  12. One-to-Many • Most common type of relationship • One record in Table A links to multiple records in Table B • 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. • 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.

  13. Many-to-Many • Multiple records in Table A are linked to multiple records in Table B • 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.

  14. Function of the Junction Table • A junction table is used with many to many relationships to join primary key fields of multiple tables • 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

More Related