Top Banner
Relational Database Example in Access - Order System Please use speaker notes for additional information!
12

Relational Database Example in Access - Order System Please use speaker notes for additional information!

Mar 28, 2015

Download

Documents

Donna Riches
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Relational Database Example in Access - Order System Please use speaker notes for additional information!

Relational Database Example in Access - Order System

Please use speaker notes for additional information!

Page 2: Relational Database Example in Access - Order System Please use speaker notes for additional information!

The inventory table (inven) contains all information directly related to the items we carry. The primary key is itemno and all elements of the table relate directly to itemno. The department table (department) was created because it would not meet the rules of third normal form to carry the department name and manager on the inven table because they relate to the department number rather than to the itemno.

The customer table (invcust) carries all information related to the customer. The primary key is custid. We could not carry the information about the sales representatives such as name and commission rate on this table because they relate to the sales representative number not to the custid. Therefore we created a new sales representative table (salesrep).

Orders have header information that applies to the whole order and line item information that applies to the particular item that is being ordered. The relationship between the order header and the order line items is a one to many relationship. One order has many line items but each line item belongs to one order. Therefore this system has an order header table (orderz) that contains information about the order such as order number, customer number and the date of the order. It also has an order line item table (ordline) that contains the order number, the item number of the item being ordered and the number ordered. Because of the one to many relationship this table has a primary key consisting of the order number and the item number.

Table designTable design

Page 3: Relational Database Example in Access - Order System Please use speaker notes for additional information!

Table: invenTable: inven

The ItemNo is the primary key for this table.

Page 4: Relational Database Example in Access - Order System Please use speaker notes for additional information!

Table: invcustTable: invcust

The Custid is the primary key for this table.

Notice Indexed is Yes with no duplicates.

Page 5: Relational Database Example in Access - Order System Please use speaker notes for additional information!

There is a one to many relationship between the order header table (orderz) and the order line item table (ordline). This means for every order there can be multiple line items, but for each line item there is only one order. I can find out the line items by going into the ordline table and retrieving all records that match the order number for a given order. Because there are multiple line items with the same order number, I have to use the combination or order number and item number to make a unique primary key.

Tables: orderz & ordline

Tables: orderz & ordline

Ordno is the primary key.

Ordno and Itemno are the primary keys.

Page 6: Relational Database Example in Access - Order System Please use speaker notes for additional information!

The primary key is Slsrep.

Tables: Salesrep & Department

Tables: Salesrep & Department

The primary key is Dept.

Page 7: Relational Database Example in Access - Order System Please use speaker notes for additional information!

RelationshipsRelationships

Page 8: Relational Database Example in Access - Order System Please use speaker notes for additional information!

Query: Inven & DepartmentQuery: Inven & Department

SELECT Inven.ItemNo, Inven.ItemName, Inven.Dept, Department.Deptname, Department.ManagerFROM Department INNER JOIN Inven ON Department.Dept = Inven.Dept;

SELECT ItemNo, ItemName, Inven.Dept, Deptname, ManagerFROM Inven, DepartmentWHERE Department.Dept = Inven.Dept;

Access SQL code.

My SQL code.

From inven. From

department.

Page 9: Relational Database Example in Access - Order System Please use speaker notes for additional information!

Queries: Orderz & InvcustQueries: Orderz & Invcust

SELECT Orderz.Ordno, Orderz.Custid, Invcust.Custname, Orderz.OrdateFROM Invcust INNER JOIN Orderz ON Invcust.Custid = Orderz.Custid;

SELECT Ordno, Orderz.Custid, Custname, OrdateFROM Orderz, InvCustWHERE Invcust.Custid = Orderz.Custid;

Access SQL code

My SQL code

Custname from Invcust table - the rest from Orderz table.

Page 10: Relational Database Example in Access - Order System Please use speaker notes for additional information!

SELECT Orderz.Ordno, Orderz.Custid, Orderz.Ordate, Ordline.Itemno, Ordline.NumordFROM Orderz INNER JOIN Ordline ON Orderz.Ordno = Ordline.Ordno;

SELECT Orderz.Ordno, Custid, Ordate, Itemno, NumordFROM Orderz, OrdlineWHERE Orderz.Ordno = Ordline.Ordno;

Query: Orderz & OrdlineQuery: Orderz & Ordline

Access SQL code

My SQL code

From Orderz From

ordline

Page 11: Relational Database Example in Access - Order System Please use speaker notes for additional information!

SELECT Orderz.Ordno, Ordline.Itemno, Inven.ItemName, Ordline.NumordFROM Inven INNER JOIN (Orderz INNER JOIN Ordline ON Orderz.Ordno = Ordline.Ordno) ON Inven.ItemNo = Ordline.Itemno;

Query: Orderz, Ordline, InvenQuery: Orderz, Ordline, Inven

SELECT Orderz.Ordno, Ordline.Itemno, Inven.ItemName, Ordline.NumordFROM Orderz, Ordline, InvenWHERE Orderz.Ordno = Ordline.Ordno AND Inven.ItemNo = Ordline.Itemno;

Access SQL My SQL

Page 12: Relational Database Example in Access - Order System Please use speaker notes for additional information!

Query on 4 tables

Query on 4 tables

SELECT Orderz.Ordno, Orderz.Custid, Invcust.Custname, Orderz.Ordate, Ordline.Itemno, Inven.ItemName, Ordline.NumordFROM (Invcust INNER JOIN Orderz ON Invcust.Custid = Orderz.Custid) INNER JOIN (Inven INNER JOIN Ordline ON Inven.ItemNo = Ordline.Itemno) ON Orderz.Ordno = Ordline.Ordno;

SELECT Orderz.Ordno, Orderz.Custid, Custname, Ordate, Ordline.Itemno, ItemName, NumordFROM Invcust, Orderz, Ordline, InvenWHERE Invcust.Custid = Orderz.Custid AND Inven.ItemNo = Ordline.Itemno AND Orderz.Ordno = Ordline.Ordno;

Access SQL

My SQL