+ All Categories
Home > Documents > Rel Order Examp

Rel Order Examp

Date post: 02-Apr-2018
Category:
Upload: gopal-patel
View: 219 times
Download: 0 times
Share this document with a friend

of 12

Transcript
  • 7/27/2019 Rel Order Examp

    1/12

    Relational Database Example in

    Access - Order System

    Please use speaker notes for

    additional information!

  • 7/27/2019 Rel Order Examp

    2/12

    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 nameand 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 wecreated 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 containsinformation 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

  • 7/27/2019 Rel Order Examp

    3/12

    Table: inven

    The ItemNo is the primary

    key for this table.

  • 7/27/2019 Rel Order Examp

    4/12

    Table: invcust

    The Custid is theprimary key for this

    table.

    Notice Indexed is Yes with

    no duplicates.

  • 7/27/2019 Rel Order Examp

    5/12

    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 ordernumber and item number to make a unique primary key.

    Tables: orderz &

    ordlineOrdno

    is the

    primary

    key.

    Ordno and Itemno

    are the primary

    keys.

  • 7/27/2019 Rel Order Examp

    6/12

    The primary key

    is Slsrep.

    Tables: Salesrep

    & Department

    The primary key is

    Dept.

  • 7/27/2019 Rel Order Examp

    7/12

  • 7/27/2019 Rel Order Examp

    8/12

    Query: Inven & DepartmentSELECT 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, ManagerFROM Inven, Department

    WHERE Department.Dept = Inven.Dept;

    Access SQL code.

    My SQL code.

    From

    inven. From

    department.

  • 7/27/2019 Rel Order Examp

    9/12

    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.

  • 7/27/2019 Rel Order Examp

    10/12

    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

  • 7/27/2019 Rel Order Examp

    11/12

    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

  • 7/27/2019 Rel Order Examp

    12/12

    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 ANDOrderz.Ordno = Ordline.Ordno;

    Access

    SQL

    My

    SQL


Recommended