You are on page 1of 34

IS 6420-001: Database Theory and Design (Spring 2015)

Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Step 1:
General description of the company where the group project is being conducted, which includes: business
goals of the company and products/services provided by the company, etc.
Neutron Interactive is a performance-based marketing company that specializes in online lead generation.
The company has grown from a startup to a successful and award-winning Inc. 500 Fastest Growing
company and was recently voted one of the Best Companies to Work For by its employees through Utah
Business magazine (the third time the company has received this accolade).
Neutron Interactive operates primarily within the higher education industry and provides a high volume of
quality inquiries to private sector schools. Since 2005, the company has grown substantially, reaching $30
million in revenue within just nine years of life. Looking forward, Neutron Interactive is looking to expand its
lead generation business beyond the higher education industry.
Neutron Interactive provides in-house marketing, design, and call center management. The company has
been developing its new proprietary lead management system called Proton, which offers real-time lead
deliveries. Neutron also utilizes business intelligence software by Neustar, Fraudlogix, and LeadiD to
ensure that its clients reach their best prospects and do not waste any time on fraudulent or low-quality
leads. By offering unparalleled support for clients needs and using the latest advanced technology
available, Neutron is well positioned to become the preeminent lead generation firm in the United States.
Company Facts and Figures:
Location: Salt Lake City, Utah
Website: http://neutroninteractive.com/
Blog: http://neutroninteractive.com/happenings/
Staff: 50 employees
Project Idea: Create a vendor relationship management (VRM) database to help Neutron Interactive
improve operational efficiencies in its accounting department. The project group selected this company
because there is a significant opportunity to develop a real-world database that could be put into production
and yield immediate results.

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Step2:
Identify and report user requirements for your group project.
An Employee at Neutron Interactive can be identified by the following attributes: Employee ID (primary
key), First Name and Last Name, Department, and Email Address. One Employee can manage many
employees; however, only one manager can manage each Employee.
One Employee can create many Purchases; however, each Purchase is assigned to one Employee. A
Purchase has the Created Date, the Price, COA, and Purchase ID (primary key). A Purchase can be a
Purchase Order, a Bill, or both a Purchase Order and a Bill (overlap). A Purchase Order has a PO Number,
Date Approved, and Manager ID. A Bill has a Bill Number. Purchase ID is the primary key for Purchase
Order and for Bill.
A Vendor providesa Purchase to Neutron Interactive. A Purchase has one Vendor, whereas a Vendor can
provide many Purchases. A Vendor can be identified by the following attributes: Vendor ID (primary key),
Company Name, Address (Street, City, State, ZIP, and Country), Phone Number, Net Terms, Email
Address, EIN, and Contact at Vendor site (First Name and Last Name). A Vendor may have more than one
Email Address and there may be more than one Contact at any given Vendor site.
An Employee submits a Payment request; the Vendor receives the Payment for the Purchase. An
Employee can submit many Payment requests; however, each Payment request is assigned to one
Employee. A Payment can be identified by the following attributes: Payment ID (primary key), Payment
Date, and Amount. A Payment to a Vendor is made by either Credit Card or Check (disjoint). A Credit Card
is identified by the Type of card and the Credit Card Number. A check is identified solely by Check Number.
Payment ID is the primary key for Credit Card and for Check payment. A Vendor can receive many
Payments; however a Payment is submitted to one Vendor at a time.
For all transactions, Neutron Interactive would like to know:
1. Which Employees have made Purchases?
2. From which Vendor did the Employee make a Purchase?
3. How much did the Employee spend on each Purchase?
4. What did the Employee decide to Purchase?
5. How/When did Neutron Interactive submit payment to the Vendor for the Purchase?
By creating a Vendor Relationship Management (VRM) system, Neutron Interactive will be able to
automate some of its accounting and finance functions within the organization. The proposed VRM will
enable closer tracking of budgets and will help to ensure that managers stay within his/her departments
budget.

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Step 3:
(Conceptual Data Modeling) Draw Entity-relationship diagram based on user requirements described in
item 2 above.

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Step 4:
(Logical Database Design) Convert entity-relationship data model into relational data model.
1. Employee (employee_id, e_fname, e_lname, dept, email, manager_id)
FK (manager_id) references Employee(employee_id)
2. Purchase (purchase_id, price, COA, created_date, employee_id, vendor_id)
FK (employee_id) references Employee (employee_id)
FK (purchase_id) references Vendor (vendor_id)
3. Purchase Order (PO_purchase_id, PO_number, date_approved,manager_id)
FK (PO_purchase_id) references Purchase (purchase_id)
4. Bill (bill_purchase_id, bill_number)
FK (bill_purchase_id) references Purchase (purchase_id)
5. Vendor (vendor_id, CompName, v_fname, v_lname, street, city, state, zip, country, terms, EIN,
v_email, phone_number)
6. Payment (payment_id, amount, payment_date, vendor_id, employee_id)
FK (employee_id) references Employee (employee_id)
FK (purchase_id) references Vendor (vendor_id)
7. Credit Card Payment (cc_payment_id, type, cc_number)
FK (cc_payment_id) references Payment (payment_id)
8. Check Payment (check_payment_id, check_number)
FK (check_payment_id) references Payment (payment_id)

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Step 5:
(Implementation in Oracle) Implement relations in the relational data model developedin item 4 by
constructing tables in Oracle.
CREATE TABLE EMPLOYEE
(
EMPLOYEE_ID NUMBER(8) NOT NULL,
E_FNAME VARCHAR2(15) NOT NULL,
E_LNAME VARCHAR2(15) NOT NULL,
DEPT
VARCHAR2(15) NOT NULL,
EMAIL
VARCHAR2(30),
MANAGER_ID NUMBER(8),
CONSTRAINT EMPID_PK PRIMARY KEY(EMPLOYEE_ID),
CONSTRAINT MANID_FK FOREIGN KEY (MANAGER_ID) REFERENCES
EMPLOYEE(EMPLOYEE_ID)
);
CREATE TABLE VENDOR
(
VENDOR_ID NUMBER(8) NOT NULL,
V_COMPNAME VARCHAR2(30) NOT NULL,
V_FNAME VARCHAR2(15),
V_LNAME VARCHAR2(15),
STREET
VARCHAR2(15),
CITY
VARCHAR2(15),
STATE
VARCHAR2(10),
ZIP
NUMBER(5),
COUNTRY VARCHAR2(10),
TERMS
VARCHAR2(6),
EIN
NUMBER(9),
EMAIL
VARCHAR2(30),
PHONE_NUMBER NUMBER(12),
CONSTRAINT VENID_PK PRIMARY KEY (VENDOR_ID)
);

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

CREATE TABLE PURCHASE


(
PURCHASE_ID NUMBER(10) NOT NULL,
PRICE
NUMBER(10,2) NOT NULL,
COA
NUMBER(5,1) NOT NULL,
CREATED_DATE DATE NOT NULL,
EMPLOYEE_ID NUMBER(8),
VENDOR_ID NUMBER(8),
CONSTRAINT PURID_PK PRIMARY KEY(PURCHASE_ID),
CONSTRAINT P_EMPID_FK FOREIGN KEY (EMPLOYEE_ID) REFERENCES
EMPLOYEE(EMPLOYEE_ID),
CONSTRAINT P_VENID_FK FOREIGN KEY (VENDOR_ID) REFERENCES VENDOR(VENDOR_ID)
);
CREATE TABLE PURCHASE_ORDER
(
PO_PURCHASE_ID NUMBER(10) NOT NULL,
PO_NUMBER VARCHAR2(20) NOT NULL,
DATE_APPROVED DATE,
MANAGER_ID NUMBER(8),
CONSTRAINT PO_PURID_PK PRIMARY KEY(PO_PURCHASE_ID),
CONSTRAINT PO_PURID_FK FOREIGN KEY (PO_PURCHASE_ID) REFERENCES
PURCHASE(PURCHASE_ID)
);
CREATE TABLE BILL
(
BILL_PURCHASE_ID NUMBER(10) NOT NULL,
BILL_NUMBER VARCHAR2(20),
CONSTRAINT BILL_PURID_PK PRIMARY KEY(BILL_PURCHASE_ID),
CONSTRAINT BILL_PURID_FK FOREIGN KEY (BILL_PURCHASE_ID) REFERENCES
PURCHASE(PURCHASE_ID)
);

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

CREATE TABLE PAYMENT


(
PAYMENT_ID NUMBER(10) NOT NULL,
AMOUNT
NUMBER(10,2) NOT NULL,
PAYMENT_DATE DATE NOT NULL,
EMPLOYEE_ID NUMBER(8),
VENDOR_ID NUMBER(8),
CONSTRAINT PAYID_PK PRIMARY KEY(PAYMENT_ID),
CONSTRAINT PAY_EMPID_FK FOREIGN KEY (EMPLOYEE_ID) REFERENCES
EMPLOYEE(EMPLOYEE_ID),
CONSTRAINT PAY_VENID_FK FOREIGN KEY (VENDOR_ID) REFERENCES VENDOR(VENDOR_ID)
);
CREATE TABLE CREDIT_CARD_PAYMENT
(
CC_PAYMENT_ID NUMBER(10) NOT NULL,
TYPE
VARCHAR2(10) NOT NULL,
CC_NUMBER NUMBER(16) NOT NULL,
CONSTRAINT CC_PAYID_PK PRIMARY KEY(CC_PAYMENT_ID),
CONSTRAINT CC_PAYID_FK FOREIGN KEY (CC_PAYMENT_ID) REFERENCES
PAYMENT(PAYMENT_ID)
);
CREATE TABLE CHECK_PAYMENT
(
CHECK_PAYMENT_ID NUMBER(10) NOT NULL,
CHECK_NUMBER NUMBER(6) NOT NULL,
CONSTRAINT CHECK_PAYID_PK PRIMARY KEY(CHECK_PAYMENT_ID),
CONSTRAINT CHECK_PAYID_FK FOREIGN KEY (CHECK_PAYMENT_ID) REFERENCES
PAYMENT(PAYMENT_ID)
);

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Step 6:
Reverse engineer a physical database diagram using Oracle SQL Developer.

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Step 7:
Populate sample data into the database.
/* CREATING SEQUENCE FOR THE EMPLOYEE_ID, EMPLOYEE TABLE*/
CREATE SEQUENCE SEQ_EMPLOYEE START WITH 10000000 INCREMENT BY 1 NOCACHE
NOCYCLE;
/* CREATING TRIGGER FOR INSERTING THE EMPLOYEE_ID, EMPLOYEE TABLE*/
CREATE OR REPLACE TRIGGER TRG_EMPLOYEE BEFORE
INSERT ON EMPLOYEE FOR EACH ROW BEGIN
SELECT SEQ_EMPLOYEE.NEXTVAL INTO :NEW.EMPLOYEE_ID FROM DUAL;
END;
/* INSERTING VALUES INTO THE TABLE : EMPLOYEE */
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Daniel',
'Caffee',
'Executive',
'dan@neutroninteractive.com',
NULL
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Felicia',
'Romney',
'Client Services',
'felicia@neutroninteractive.com',
10000000
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Dave',
'Freeman',
'Marketing',
'dave@neutroninteractive.com',
10000000
);
INSERT

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

INTO EMPLOYEE VALUES


(
NULL,
'Angela',
'Matthes',
'Admin',
'angela@neutroninteractive.com',
NULL
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Shaun',
'Kruger',
'Tech',
'shaunk@neutroninteractive.com',
10000003
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Greg',
'Meador',
'Executive',
'gregm@neutroninteractive.com',
10000004
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'George',
'M',
'IT',
'george@neutroninteractive.com',
10000004
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Ryan',
'WS',
'IT',
'ryan@neutroninteractive.com',
10

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

NULL
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Rachael',
'Woolsey',
'Marketing',
'rachael@neutroninteractive.com',
NULL
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Daniel',
'James',
'Sales',
'daniel@neutroninteractive.com',
10000001
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Preethy',
'Joy',
'IT',
'preethy@neutroninteractive.com',
10000007
);
INSERT
INTO EMPLOYEE VALUES
(
NULL,
'Sara',
'T',
'Sales',
'sara@neutroninteractive.com',
10000009
);

11

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

/* CREATING SEQUENCE FOR THE VENDOR_ID, VENDOR TABLE*/


CREATE SEQUENCE SEQ_VENDOR START WITH 20000000 INCREMENT BY 1 NOCACHE
NOCYCLE;
/* CREATING TRIGGER FOR INSERTING THE VENDOR_ID, VENDOR TABLE*/
CREATE OR REPLACE TRIGGER TRG_VENDOR BEFORE
INSERT ON VENDOR FOR EACH ROW BEGIN
SELECT SEQ_VENDOR.NEXTVAL INTO :NEW.VENDOR_ID FROM DUAL;
END;
/*INSERTING VALUES INTO THE VENDOR TABLE*/
INSERT
INTO VENDOR VALUES
(
NULL,
'Neustar',
'Nelsie',
'Ubalde',
'3E',
'Murray',
'UT',
'84107',
'USA',
'NET30',
234675098,
'nelsie.ubalde@neustar.biz',
017034644274
);
INSERT
INTO VENDOR VALUES
(
NULL,
'Advanced Systems Group',
'Tessy',
'John',
'11052S',
'South Jordan',
'UT',
'84095',
'USA',
'NET0',
987675098,
'tessy.john@asg.com',
015987558888
);
INSERT
INTO VENDOR VALUES
12

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

(
NULL,
'IMFT',
'Freddy',
'Philip',
'East Winsor',
'April Drive',
'CT',
'11095',
'USA',
'NET3',
909987668,
'freddy.philip@imft.com',
016555909988
);
INSERT
INTO VENDOR VALUES
(
NULL,
'Advanced Systems Group',
'Christina',
'Joy',
'Lincoln Ave',
'Los Angeles',
'CA',
'12085',
'USA',
'NET51',
777675098,
'christina.joy@asg.com',
015980898880
);
INSERT
INTO VENDOR VALUES
(
NULL,
'Verisign',
'Sony',
'Thomas',
'Mark Ave',
'Chicago',
'IL',
'72085',
'USA',
'NET5',
777675098,
'sonythomas@vsn.com',
13

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

015777898880
);
INSERT
INTO VENDOR VALUES
(
NULL,
'Verisign',
'Martin',
'R K',
'Vine Street',
'Phoenix',
'AZ',
'78088',
'USA',
'NET11',
799675098,
'martinrk@vsn.com',
015986770880
);
INSERT
INTO VENDOR VALUES
(
NULL,
'ICANN',
'Maria',
'T',
'State Street',
'Tuscon',
'AZ',
'78087',
'USA',
'NET1',
759675098,
'maria@icann.com',
067986770880
);
INSERT
INTO VENDOR VALUES
(
NULL,
'Afilias',
'Mary',
'Thomas',
'SS Drive',
'San Francisco',
'CA',
'38088',
14

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

'USA',
'NET30',
767675098,
'mary@afilias.com',
018016770880
);
INSERT
INTO VENDOR VALUES
(
NULL,
'Comodo',
'Niel',
'R K',
'Vine Street',
'Phoenix',
'AZ',
'78088',
'USA',
'NET11',
499675098,
'comodo@vsn.com',
015986734880
);
INSERT
INTO VENDOR VALUES
(
NULL,
'TRUSTe',
'Angel',
'K',
'SSN Street',
'San Diego',
'CA',
'78011',
'USA',
'NET5',
199675098,
'angel@truste.com',
015342770880
);

15

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

/* CREATING SEQUENCE FOR THE VENDOR_ID, VENDOR TABLE*/


CREATE SEQUENCE SEQ_PURCHASE START WITH 3000000000 INCREMENT BY 1 NOCACHE
NOCYCLE;
/* CREATING TRIGGER FOR INSERTING THE VENDOR_ID, VENDOR TABLE*/
CREATE OR REPLACE TRIGGER TRG_PURCHASE BEFORE
INSERT ON PURCHASE FOR EACH ROW BEGIN
SELECT SEQ_PURCHASE.NEXTVAL INTO :NEW.PURCHASE_ID FROM DUAL;
END;
/*INSERTING VALUES INTO THE PURCHASE TABLE*/
INSERT
INTO PURCHASE VALUES
(
NULL,
27009,
1000.4,
'01-FEB-2014',
10000002,20000002
);
INSERT
INTO PURCHASE VALUES
(
NULL,
1409.22,
1410.4,
'12-DEC-2014',
10000001,20000002
);
INSERT INTO PURCHASE VALUES
(NULL,7950,6301,'30-DEC-2014',10000003,20000003
);
INSERT INTO PURCHASE VALUES
(NULL,5938,1401,'27-AUG-2014',10000004,20000004
);
INSERT INTO PURCHASE VALUES
(NULL,300,1438,'17-AUG-2014',10000001,20000002
);
INSERT
INTO PURCHASE VALUES
(
NULL,
2670,
1000.4,
'01-FEB-2014',
10000002,20000002
);
16

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

INSERT
INTO PURCHASE VALUES
(
NULL,
200,
1410.4,
'12-DEC-2014',
10000001,20000002
);
INSERT
INTO PURCHASE VALUES
(
NULL,
987.22,
6301,
'30-DEC-2014',
10000003,20000003
);
INSERT
INTO PURCHASE VALUES
(
NULL,
97.22,
1401,
'27-AUG-2014',
10000004,20000004
);
INSERT
INTO PURCHASE VALUES
(
NULL,
497.2,
1438,
'17-AUG-2014',
10000001,20000002
);
INSERT INTO PURCHASE VALUES
(NULL,411,1401,'15-AUG-2011',10000009,20000008
);
INSERT
INTO PURCHASE VALUES
(
NULL,
200.2,
1000.4,
'10-AUG-2012',
10000008,20000009
17

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

);
INSERT INTO PURCHASE VALUES
(NULL,410,1438,'17-AUG-2014',10000006,20000007
);
INSERT INTO PURCHASE VALUES
(NULL,411,1401,'15-AUG-2011',10000007,20000005
);
INSERT
INTO PURCHASE VALUES
(
NULL,
987.22,
6301,
'30-DEC-2014',
10000005,20000000
);
INSERT INTO PURCHASE VALUES
(NULL,980,6301,'30-JUL-2013',10000003,20000001
);
INSERT
INTO PURCHASE VALUES
(
NULL,
497.2,
1438,
'17-AUG-2012',
10000001,20000006
);
INSERT
INTO PURCHASE VALUES
(
NULL,
600,
1438,
'10-MAR-2015',
10000006,20000007
);
INSERT
INTO PURCHASE VALUES
(
NULL,
750,
200,
'17-FEB-2015',
10000003,20000005
);
INSERT INTO PURCHASE VALUES
18

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

(NULL, 900, 200,'11-JAN-2015',10000003,20000005


);
INSERT INTO PURCHASE VALUES
(NULL, 450, 300,'21-JAN-2015',10000003,20000006
);
INSERT INTO PURCHASE VALUES
(NULL, 450, 300,'10-MAR-2015',10000003,20000006
);
/*INSERTING VALUES INTO PURCHASE_ORDER TABLE*/
INSERT
INTO PURCHASE_ORDER VALUES
(
3000000005,
'QUO-637496SXNOM',
'12-SEP-2014',
10000000
);
INSERT
INTO PURCHASE_ORDER VALUES
(
3000000006,
'QUO-98990HHNOM',
'27-DEC-2014',
10000003
);
INSERT INTO PURCHASE_ORDER VALUES
(3000000009,'QUO-98990HHNOM',NULL, NULL
);
INSERT INTO PURCHASE_ORDER VALUES
(3000000000,'QUO-98990KLNOM',NULL, NULL
);
INSERT INTO PURCHASE_ORDER VALUES
(3000000001,'QUO-556690HHNOM',NULL, NULL
);
INSERT INTO PURCHASE_ORDER VALUES
(3000000002,'QUO-99877HHNOM',NULL, NULL
);
INSERT
INTO PURCHASE_ORDER VALUES
(
3000000010,
'QUO-99877HHNOM',
'16-AUG-2011',
10000004
);
INSERT
19

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

INTO PURCHASE_ORDER VALUES


(
3000000011,
'QUO-99877WWNOM',
'10-AUG-2014',
10000004
);
INSERT
INTO PURCHASE_ORDER VALUES
(
3000000012,
'QUO-13877WWNOM',
'18-AUG-2014',
10000004
);
INSERT
INTO PURCHASE_ORDER VALUES
(
3000000013,
'QUO-01877WWNOM',
'16-AUG-2014',
10000009
);
INSERT INTO PURCHASE_ORDER VALUES
( 3000000017, 'QUO-6374SXNOM', NULL, NULL
);
INSERT
INTO PURCHASE_ORDER VALUES
(
3000000018,
'QUO-6374HHNOM',
'20-FEB-2015',
10000002
);
INSERT
INTO PURCHASE_ORDER VALUES
(
3000000019,
'QUO-6374SHNOM',
'12-JAN-2015',
10000002
);
/*INSERTING VALUES INTO BILL TABLE*/
INSERT
INTO BILL VALUES
(
20

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

3000000007,
'INV-0088341'
);
INSERT INTO BILL VALUES
(3000000008, 'TIC-0000025486'
);
INSERT INTO BILL VALUES
(3000000003, 'YIC-009822'
);
INSERT INTO BILL VALUES
(3000000004, 'INV-045509822'
);
INSERT INTO BILL VALUES
(3000000014, 'TIC-040509822'
);
INSERT INTO BILL VALUES
(3000000015, 'INV-045509822'
);
INSERT INTO BILL VALUES
(3000000016, 'TIC-145509822'
);
INSERT INTO BILL VALUES
(3000000020, 'INV-0225509822'
);
INSERT INTO BILL VALUES
(3000000021, 'TIC-04099822'
);
INSERT INTO BILL VALUES
(3000000010, 'INV-0509822'
);
/* CREATING SEQUENCE FOR THE PAYMENT_ID, PAYMENT TABLE*/
CREATE SEQUENCE SEQ_PAYMENT START WITH 4000000000 INCREMENT BY 1 NOCACHE
NOCYCLE;
/* CREATING TRIGGER FOR INSERTING THE PAYMENT_ID, VENDOR TABLE*/
CREATE OR REPLACE TRIGGER TRG_PAYMENT BEFORE
INSERT ON PAYMENT FOR EACH ROW BEGIN
SELECT SEQ_PAYMENT.NEXTVAL INTO :NEW.PAYMENT_ID FROM DUAL;
END;
/*INSERTING VALUES INTO PAYMENT TABLE*/
INSERT
INTO PAYMENT VALUES
(
NULL,
5938,
21

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

'28-AUG-2014',
10000004,20000004
);
INSERT INTO PAYMENT VALUES
(NULL,300,'18-AUG-2014', 10000001,20000002
);
INSERT INTO PAYMENT VALUES
(NULL,2670,'02-FEB-2014', 10000002,20000002
);
INSERT INTO PAYMENT VALUES
(NULL,200,'15-DEC-2014', 10000001,20000002
);
INSERT INTO PAYMENT VALUES
(NULL,987.22,'31-DEC-2014', 10000003,20000003
);
INSERT INTO PAYMENT VALUES
(NULL,497.2,'20-AUG-2014', 10000001,20000002
);
INSERT INTO PAYMENT VALUES
(NULL,411,'20-AUG-2011', 10000009,20000008
);
INSERT INTO PAYMENT VALUES
(NULL,200.2,'12-AUG-2012', 10000008,20000009
);
INSERT INTO PAYMENT VALUES
(NULL,410,'18-AUG-2014', 10000006,20000007
);
INSERT INTO PAYMENT VALUES
(NULL,411,'16-AUG-2011', 10000007,20000005
);
INSERT INTO PAYMENT VALUES
(NULL,987.22,'31-DEC-2014', 10000005,20000000
);
INSERT INTO PAYMENT VALUES
(NULL,497.2,'22-AUG-2012', 10000001,20000006
);
INSERT INTO PAYMENT VALUES
(NULL,980,'01-AUG-2013', 10000003,20000001
);
INSERT INTO PAYMENT VALUES
( NULL, 750, '18-FEB-2015', 10000003,20000005
);
INSERT INTO PAYMENT VALUES
( NULL, 900, '18-JAN-2015', 10000003,20000005
);
INSERT INTO PAYMENT VALUES
( NULL, 450, '22-JAN-2015', 10000003,20000006
22

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

);
INSERT INTO PAYMENT VALUES
( NULL, 450, '11-MAR-2015', 10000003,20000006
);
/*INSERTING VALUES INTO CREDIT_CARD_PAYMENT TABLE*/
INSERT
INTO CREDIT_CARD_PAYMENT VALUES
(
4000000000,
'AMEX',
372737957732016
);
INSERT INTO CREDIT_CARD_PAYMENT VALUES
(4000000002,'VISA', 372798745600016
);
INSERT
INTO CREDIT_CARD_PAYMENT VALUES
(
4000000003,
'MASTERCARD',
1327379577320163
);
INSERT
INTO CREDIT_CARD_PAYMENT VALUES
(
4000000006,
'MASTERCARD',
9327379577320163
);
INSERT INTO CREDIT_CARD_PAYMENT VALUES
(4000000007,'VISA', 4532379577320163
);
INSERT INTO CREDIT_CARD_PAYMENT VALUES
(4000000008,'AMEX', 5027379577320163
);
INSERT INTO CREDIT_CARD_PAYMENT VALUES
(4000000009,'AMEX', 7887379577320163
);
INSERT INTO CREDIT_CARD_PAYMENT VALUES
(4000000010,'VISA', 2117379577320163
);
/*INSERTING VALUES INTO CHECK_PAYMENT TABLE*/
INSERT
INTO CHECK_PAYMENT VALUES
(
23

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

4000000001,
5448
);
INSERT INTO CHECK_PAYMENT VALUES
(4000000004, 3341
);
INSERT INTO CHECK_PAYMENT VALUES
(4000000005, 1222
);
INSERT INTO CHECK_PAYMENT VALUES
(4000000011, 1272
);
INSERT INTO CHECK_PAYMENT VALUES
(4000000012, 1332
);
COMMIT;
Displaying the tables after INSERT :
1. EMPLOYEE : SELECT * FROM EMPLOYEE;

24

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

2. VENDOR : SELECT * FROMVENDOR;

3. PURCHASE: SELECT * FROM PURCHASE;

25

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

4. PURCHASE_ORDER: SELECT * FROM PURCHASE_ORDER;

5. BILL: SELECT * FROM BILL;

26

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

6. PAYMENT: SELECT * FROM PAYMENT;

7. CREDIT_CARD_PAYMENT: SELECT * FROM CREDIT_CARD_PAYMENT;

8. CHECK_PAYMENT: SELECT * FROM CHECK_PAYMENT;

27

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Step 8:
Create and demonstrate at least 4 frequently used SQL queries. Implement at least 1 additional query into
a Database View object.
Query 1: Create a view for evaluating the payment patterns in last 3 months:
Business function: For tracking the payments created by the employees and to evaluate the companys
expenses for the past 3 months.
Creating the view:
CREATE OR REPLACE VIEW VW_COMPANY_PAYMENTS
AS
SELECT P.EMPLOYEE_ID,
E.E_FNAME,
E.E_LNAME,
E.DEPT,
AMOUNT,
PAYMENT_DATE,
V_COMPNAME
FROM PAYMENT P
JOIN VENDOR V
ON P.VENDOR_ID=V.VENDOR_ID
JOIN EMPLOYEE E
ON P.EMPLOYEE_ID=E.EMPLOYEE_ID
WHERE (SYSDATE - PAYMENT_DATE)<90;
Querying the view:
SELECT * FROM VW_COMPANY_PAYMENTS;
Output:

28

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Query 2: What is the amount spent by a specific employee, grouped by Chart of Account, in a given
time period?
Business function: Currently, there is no way to track spend by employee or department in Neutron
Interactives accounting system. The work around involves time-consuming pivots of CSV exports from the
accounting software and the expense reporting software. Each software has an API that could be
integrated with this database to perform this query, saving a substantial amount of time. This report would
be useful if pulled monthly, quarterly and/or annually and would be compared against the respective
budgets.
SELECT EMPLOYEE_ID, COA,
SUM(PRICE) AS TOTAL
FROM PURCHASE NATURAL JOIN PAYMENT
WHERE EMPLOYEE_ID = 10000001
AND PAYMENT_DATE BETWEEN TO_DATE('01-MAR-13','DD-MON-YY') AND TO_DATE('01-MAR-15',
'DD-MON-YY')
GROUP BY COA, EMPLOYEE_ID;
Output:

29

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Query 3: What is the amount spent by a specific employee, per vendor, in a given time period?
Business function: This query supports query #1 byproviding additional information to the Accounting
Department and the employee regarding total spend. It will also be useful to verify that the amounts are
correct for vendors under contract with set recurring charges.
SELECT EMPLOYEE_ID, V_COMPNAME, SUM(AMOUNT) AS TOTAL
FROM PAYMENT NATURAL JOIN VENDOR
WHERE EMPLOYEE_ID = 10000003
AND PAYMENT_DATE BETWEEN to_date('01-MAR-13','DD-MON-YY') AND to_date('01-MAR-15', 'DDMON-YY')
GROUP BY V_COMPNAME, EMPLOYEE_ID ;
Output:

30

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Query 4: Are there any vendor relationships that could be consolidated?


Business function: Viewing a list of vendors for a specific Chart of Account provides insight into whether or
not there may be vendor relationships that could be consolidated (e.g. using one domain hosting service
instead of three). For larger contracts, better pricing can often be achieved by moving the business to a
single vendor. In the past, Neutron has had relationships with multiple vendors that were not strategic, but
rather happenstance resulting from employee turnover. This query would provide useful information for an
employee to see what other vendor relationships are being used to provide similar services.
SELECT V_COMPNAME,
VENDOR_ID
FROM VENDOR NATURAL
JOIN PURCHASE
WHERE COA = 1401
GROUP BY V_COMPNAME,
VENDOR_ID ;
Output:

Query 5: What are the historical transactions for a specified vendor?


Business function: Neutron Interactives current accounting system does not provide reporting of
transaction history, detail, etc., for credit card expenses. Transaction history is only reported through the
Accounts Payable module, which requires a bill be created first and then matched to a bill payment. A large
portion of Neutrons spend is made without the creation of a bill (e.g. travel expenses, hosting services,
etc.)
SELECT *
FROM PURCHASE NATURAL JOIN PAYMENT
WHERE VENDOR_ID = 20000007;
Output:

31

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Query 6: Which vendors are inactive (no transactions in the past two years)?
Business function: Neutron Interactive is interested in maintaining a list of inactive vendors to enable a
quick reactivation of a vendor account should the need arise. This query also helps the company keep an
accurate historical record of inactive/retired accounts.
SELECT V_COMPNAME, PAYMENT_DATE
FROM VENDOR NATURAL JOIN PAYMENT
WHERE SYSDATE - PAYMENT.PAYMENT_DATE > 730;
Output:

Query 7: List vendors that Neutron Interactive is required to file a 1099 and related information.
Business function: By federal law, Neutron Interactive is required to file a 1099 for certain vendors who
provide a service greater than $600 in a calendar year. Neutron collects W-9s (and resultant EINs) only for
vendors that require a 1099 at year-end. One example of this query would be to show all vendors with EIN
and sum of purchases > $600 in 2014 with address.
SELECT V_COMPNAME, EIN, STREET, CITY, STATE, COUNTRY, SUM(AMOUNT) AS TOTAL
FROM VENDOR NATURAL JOIN PAYMENT
WHERE (PAYMENT_DATE BETWEEN TO_DATE('01-JAN-13','DD-MON-YY') AND TO_DATE('31-DEC13', 'DD-MON-YY'))
AND EIN IS NOT NULL
GROUP BY V_COMPNAME, EIN, STREET, CITY, STATE, COUNTRY
HAVING SUM(AMOUNT)>=600
ORDER BY TOTAL ;
Output:

32

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Query 8: Which Purchase Orders have not been approved?


Business function: The accounting department at Neutron Interactive needs to be aware of any/all
purchase orders that have not been approved. Using this query will allow Neutron Interactive to identify
potential patterns and issues regarding denied/unapproved purchase orders.
SELECT *
FROM PURCHASE_ORDER
WHERE DATE_APPROVED IS NULL;
Output:

Query 9: Which are the highest paid vendors?


Business function: This query helps the accounting department at Neutron Interactive identify where the
company spends the most money. This query would also be useful in tracking trends over time.
SELECT VENDOR.V_COMPNAME,
SUM(PURCHASE.PRICE) AS TOTAL
FROM VENDOR NATURAL JOIN PURCHASE
GROUP BY VENDOR.V_COMPNAME
ORDER BY TOTAL DESC;
Output:

33

IS 6420-001: Database Theory and Design (Spring 2015)


Group 3 Project: Angela Matthes, Daniel James, Preethy Joy, Rachael Woolsey

Query 10: What is the total spend, in a given period of time, grouped by Chart of Account?
Business function: Neutron Interactive maintains its accounting books on an accrual basis. Viewing
payments grouped by chart or account would allow Neutron to see spending trends on a cash basis. This
information will be useful for cash flow analysis.
SELECT COA,
SUM(PRICE) AS TOTAL
FROM PURCHASE
GROUP BY COA;
Output:

34