Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Queries (query 12) Display vendor contact info (contact person and phone number) for inventory products (relationship query) Query: Inventory.

Similar presentations


Presentation on theme: "Relational Queries (query 12) Display vendor contact info (contact person and phone number) for inventory products (relationship query) Query: Inventory."— Presentation transcript:

1 Relational Queries (query 12) Display vendor contact info (contact person and phone number) for inventory products (relationship query) Query: Inventory Product Info

2 EMPLOYEES Employee#* Department DEPARTMENTS Department name* Inventory Product number* PURCHASE ORDERS Product number Emp Number M 1 M Relational Concepts Employees of a department make orders for requested products Not all tables are linked Only related ones Two tables can have multiple relationships Table relationships/links can be One-to-many One department can have many employees One-to-one In Access, can’t be many-to-many

3 Steps for Designing a Database
Understand application Determine the entities in your business Determine what tables you need What properties (fields) does each table have? What is the key of each table? How to link tables?

4 Using Multiple Tables Linked fields don’t need to have the same name
E.g. Department & Department name But must contain data of same data type Field must be key in at least one table primary table vs. related table Referential Integrity: Every department in EMPLOYEES (related table) must exist in DEPARTMENTS (primary table) The link is activated by a Join operation Inner Join Left Outer Join Right Outer Join Try Vendors and Inventory

5

6

7 Using Multiple Tables How to create relationships between tables?
Relationship window Tools  Relationships Add tables to window Right Click  Show Table Remove tables from window Select Table Right Click  Hide Table Join tables Click on the field of one table and drag it over to the corresponding field in the other table A window appears that describes the relationship

8 Key Field 3 Types of Joins 1 to many Used when a record of Departments (primary (1st) table) has its Join field changed  what would happen to corresponding fields in Employees (related (2nd) table) records? If not clicked  no ref. integrity If clicked  Every record in related Table must have a matching record in primary table; two other boxes  Cascade Update  Cascade Delete

9 The 1 is for the primary table
Referential Integrity: We can’t have a record in the related table that has no matching record in the primary table Cascade Update  If join field of some record in primary table is updated then update corresponding field in related table records E.g., “Design”  “Development” in Departments, then automatically all “Design” in Employees become “Development” Cascade Delete  If record of some join field in primary table is deleted then delete corresponding records related table E.g. if we delete the “Design” department from Departments, then automatically delete all Employees record in the “Design” Department

10 Types of Joins Decide how we go about concatenating records from related tables into 1 table 3 options are given : Reason: not all records in primary table have matching records in related table E.g. Department = { (‘CSCI’, SJU), (‘MGMT’, SJU) , (‘ACCT’, CSB)} Student (name, Department) … 2 CSCI, 1 MGMT and 2 HIST Inner Join (1): includes data only from records have matches records in both tables Left Outer Join (2): includes all records from primary even those that have no matches in related Right Outer Join (3): includes all records from related even those that have no matches in primary in case referential integrity is not specified NO JOIN!

11 Types of Joins (Query that JOINS Purchase Orders & Inventory)
Drop Join and show result Inner Join: Inventory items with outstanding purchase orders Left Outer Join: All inventory items will be included even those with no outstanding purchase orders Right Outer Join: All items with outstanding purchases are included even those not in inventory NO JOIN!


Download ppt "Relational Queries (query 12) Display vendor contact info (contact person and phone number) for inventory products (relationship query) Query: Inventory."

Similar presentations


Ads by Google