Presentation on theme: "Relational Database Example in Access - Order System Please use speaker notes for additional information!"— Presentation transcript:
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 design
Table: inven The ItemNo is the primary key for this table.
Table: invcust The Custid is the primary key for this table. Notice Indexed is Yes with no duplicates.
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 Ordno is the primary key. Ordno and Itemno are the primary keys.
The primary key is Slsrep. Tables: Salesrep & Department The primary key is Dept.
Query: Inven & Department SELECT Inven.ItemNo, Inven.ItemName, Inven.Dept, Department.Deptname, Department.Manager FROM Department INNER JOIN Inven ON Department.Dept = Inven.Dept; SELECT ItemNo, ItemName, Inven.Dept, Deptname, Manager FROM Inven, Department WHERE Department.Dept = Inven.Dept; Access SQL code. My SQL code. From inven. From department.
Queries: Orderz & Invcust SELECT Orderz.Ordno, Orderz.Custid, Invcust.Custname, Orderz.Ordate FROM Invcust INNER JOIN Orderz ON Invcust.Custid = Orderz.Custid; SELECT Ordno, Orderz.Custid, Custname, Ordate FROM Orderz, InvCust WHERE Invcust.Custid = Orderz.Custid; Access SQL code My SQL code Custname from Invcust table - the rest from Orderz table.
SELECT Orderz.Ordno, Orderz.Custid, Orderz.Ordate, Ordline.Itemno, Ordline.Numord FROM Orderz INNER JOIN Ordline ON Orderz.Ordno = Ordline.Ordno; SELECT Orderz.Ordno, Custid, Ordate, Itemno, Numord FROM Orderz, Ordline WHERE Orderz.Ordno = Ordline.Ordno; Query: Orderz & Ordline Access SQL code My SQL code From Orderz From ordline
SELECT Orderz.Ordno, Ordline.Itemno, Inven.ItemName, Ordline.Numord FROM Inven INNER JOIN (Orderz INNER JOIN Ordline ON Orderz.Ordno = Ordline.Ordno) ON Inven.ItemNo = Ordline.Itemno; Query: Orderz, Ordline, Inven SELECT Orderz.Ordno, Ordline.Itemno, Inven.ItemName, Ordline.Numord FROM Orderz, Ordline, Inven WHERE Orderz.Ordno = Ordline.Ordno AND Inven.ItemNo = Ordline.Itemno; Access SQL My SQL
Query on 4 tables SELECT Orderz.Ordno, Orderz.Custid, Invcust.Custname, Orderz.Ordate, Ordline.Itemno, Inven.ItemName, Ordline.Numord FROM (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, Numord FROM Invcust, Orderz, Ordline, Inven WHERE Invcust.Custid = Orderz.Custid AND Inven.ItemNo = Ordline.Itemno AND Orderz.Ordno = Ordline.Ordno; Access SQL My SQL