Database Design
Database Design
Database Design
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.
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.
Step 3:
(Conceptual Data Modeling) Draw Entity-relationship diagram based on user requirements described in
item 2 above.
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)
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)
);
Step 6:
Reverse engineer a physical database diagram using Oracle SQL Developer.
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
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
(
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
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
'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
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
);
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
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
'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
);
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
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
25
26
27
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
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
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
31
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
33
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