3. Table of Contents
1. Introduction:......................................................................................................................................................4
2. Problem Statement:............................................................................................................................................4
3. Recommended Solution:.....................................................................................................................................4
4. Business Rules:...................................................................................................................................................5
5. ER Diagram and relationship model:....................................................................................................................5
6. Final Code:..........................................................................................................................................................7
7. Normalized Tables:...........................................................................................................................................11
8. Data Dictionary:................................................................................................................................................12
9. Reporting Queries:............................................................................................................................................14
10. Conclusion:.......................................................................................................................................................18
4. 1. Introduction
This project deals with designing and implementing a system for handling the information of
Bennett Dinning from a manager’s perspective. The café’s manager has the job to handle its 2
units i.e., Café Libro and Fast Break.
Bennett dining is one of the biggest dining services in the Oklahoma State University. In both
the café’s, they have various employees working at different categories such as Stocker, Coffee,
Hot food, Cashier and Supervisor. These employees work in different shifts with shift ID 1,2,3
etc and with time varying from 7:00 am in the morning to 3:00 pm in the evening.
Likewise, the details of all the employees such as their first name, last name etc, their leave
details, schedule for all the days, vacant positions available in both the café’s, sales of both the
café’s and inventory details of both the café’s needs to be managed by the manager.
To make the manager’s job easier, we design a database in SQL Server which contains various
tables containing the above-mentioned values and we would run several SQL queries which will
help the manager to generate several reports about both the café’s.
2. ProblemStatement
Before the database was built, the manager had a tedious task in finding out various details like
for hiring new employees, finding out the number of open positions, finding out the stock to be
ordered to be kept in the inventory.
It used to get very difficult for the manager for situations if he had to hire some new employees
by maintaining all the data in the software such as Microsoft Excel etc.
All the calculations regarding the sales the 2 different dates and other operations had to be
done either using calculator or manually.
3. RecommendedSolution
The recommended solution we have come up for the manager is by creating a database in SQL
Server which contains various tables containing the above-mentioned values and we would run
several SQL queries which would help the manager in finding out several details about both the
café’s.
This would reduce the manager’s workload by excluding the work to be done using Microsoft
Excel and by even helping him perform calculations and various other operations on the data
using the database model itself.
5. 4. Business Rules
For each unit there should be only one supervisor.
Employee can work many shifts but for a particular shift on a particular day there is only one
Employee.
An employee can work for more than one unit.
At least one employee should be there in each of the categories for any particular shift.
For any particular shift, one employee can be assigned to one position only.
Salary of the employee is calculated as (No of hours worked*8).
Value taken by the gender in the employee table can be either M or F only.
One unit can sell multiple things.
One unit can have many items in inventory.
An employee can apply for multiple leaves.
A unit can have more than one vacancies.
Other than supervisor no employee can work for more than 40 hours a week.
5. ER Diagram and relationshipmodel
12. 8. Data Dictionary
Below mentioned are the statements which define each and every column of every table
defined in our database:
Table – Employee
Employee table consists of 6 columns as mentioned below:
1. EMP_ID – This contains the employee ID with the data type Numeric with Auto Increment
2. F_Name – This field contains the employee first name with the data type Varchar
3. L_Name - This field contains the employee last name with the data type Varchar
4. Position – This field contains the position each employee is working at with the data type
Varchar.
5. Phone_Number – This field consists of phone number of each employee with the data type
Varchar.
6. Gender – This filed specifies the gender of each employee with the data type Varchar (1).
Table – Category
This table consists of 2 columns as mentioned below:
1. Category_ID - This contains the category ID with the data type Numeric with Auto Increment
2. Category_Name – This contains the name of each category with the data type Varchar.
Table – Shift
This table consists of 5 columns as mentioned below:
1. Shift_ID – This contains the shift ID for every different shift having the data type Numeric
with Auto Increment.
2. Shift_Start – This contains the shift start time with the data type DateTime.
3. Shift_End – This contains the shift end time with the data type DateTime.
4. unit_ID – This contains the unit ID for every different unit with the data type Numeric.
5. Category_ID – This contains the category ID for every category having the data type Numeric.
Table – Unit
This table consists of 5 columns as mentioned below:
1. Unit_ID – This contains the unit ID having the data type Numeric with Auto Increment.
2. Unit – This contains the unit name for every unit having the data type Varchar.
3. Unit_Location – This contains the location of every unit having the data type Varchar.
4. SUP_EMP_ID – This contains the employee ID of the supervisor for that unit with the data
type Numeric.
5. Supervisor – This stores the name of the supervisor in it with the data type Varchar.
13. Table – Schedule
This table consists of 3 columns with the details mentioned below:
1. em_id – This contains a unique numeric number assigned to each employee
2. Day – This contains the day for that schedule with the data type Day.
3. Shift_ID - This contains the shift ID for every different shift having the data type Numeric.
Table – Leave Details
This table consists of 3 columns as mentioned below:
1. Emp_id – This contains the employee ID with the data type Numeric
2. Leave_Start – This contains the leave end date with the data type DateTime.
3. Leave_End – This contains the leave end date with the data type DateTime.
Table – Item
This table consists of 6 columns as mentioned below:
1. Item_Id – This contains the item ID with the data type Numeric and auto increment.
2. Item_desc – This contains the item description with the data type Varchar.
3. Date – This column contains the date when the inventory item was ordered.
4. Unit_ID – This contains the unit ID having the data type Numeric.
5. COST_PER_UNIT – This would contain the cost of every item per unit with the data type
numeric.
6. Quantity – This would contain the quantity of items available with the data type Numeric(3).
Table – Sales
This table consists of 4 columns as mentioned below:
1. Invoice_No – This contains the InvoiceNo with the data type Numeric and auto increment.
2. Date – This contains the date of the invoice with the data type Date.
3. Unit_ID – This contains the unit ID having the data type Numeric.
4. Amount – This contains the total amount of sales with the data type Numeric.
Table – Vacancy
This table consists of 3 columns as mentioned below:
1. Shift_ID –This contains the shift ID for every different shift having the data type Numeric.
2. Category_ID –This contains the category ID for every category of work having the data type
Numeric.
3. Unit_ID – This contains the unit ID having the data type Numeric.
14. 9. Reporting Queries
Query 1: SQL Query to compare the overall salesof the two units separately.
SELECT u.UNIT_ID AS 'Id', UNIT_NAME AS 'Name', SUM(AMOUNT) as 'Total Sales'
FROM SALES s, UNIT u
WHERE s.UNIT_ID = u.UNIT_ID
GROUP BY u.UNIT_ID, UNIT_NAME
Query 2: SQL Query to calculate salary of all employeesforboth the units ifthe per hour rate is 8$.
SELECT DISTINCT (e.EMP_ID) AS 'ID', F_NAME AS 'First Name', L_NAME AS 'Last Name',
((Total_Hours)*8) AS 'Salary' FROM EMPLOYEE e, SHIFT_ s, SCHEDULE h,
(SELECT EMP_ID, SUM (NUMBER_OF_HOURS) AS 'Total_Hours' FROM SHIFT_ g,
SCHEDULE h, CATEGORY c
WHERE h.SHIFT_ID = g.SHIFT_ID
AND c.CATEGORY_ID = g.CATEGORY_ID
AND CATEGORY_NAME NOT LIKE '%SUPERVISOR%'
GROUP BY EMP_ID) i
WHERE e.EMP_ID = h.EMP_ID
AND h.SHIFT_ID = s.SHIFT_ID
AND e.EMP_ID = i.EMP_ID
15. Query 3: SQL Query to calculate the numberof employeesworkingacross all the categoriesin both
units.
SELECT UNIT_NAME AS 'Unit', CATEGORY_NAME AS 'Category', COUNT (DISTINCT(s.EMP_ID)) AS 'Number
of Employees'
FROM SHIFT_ a, CATEGORY c, SCHEDULE s, UNIT u
WHERE a.CATEGORY_ID = c.CATEGORY_ID
AND a. UNIT_ID = u.UNIT_ID
AND s.SHIFT_ID = a.SHIFT_ID
GROUP BY UNIT_NAME, CATEGORY_NAME
ORDER BY UNIT_NAME
Query 4: SQL Query to calculate the numberof employeesworkingundereach supervisor.
SELECT Unit, e.F_NAME AS 'Supervisor', Number_of_Employees
FROM EMPLOYEE e, (SELECT UNIT_NAME AS 'Unit', u.SUP_EMP_ID, COUNT (DISTINCT(s.EMP_ID)) AS '
Number_of_Employees'
FROM SHIFT_ a, CATEGORY c, SCHEDULE s, UNIT u
WHERE a.CATEGORY_ID = c.CATEGORY_ID
AND a. UNIT_ID = u.UNIT_ID
AND s.SHIFT_ID = a.SHIFT_ID
AND c.CATEGORY_NAME NOT LIKE ('%SUPERVISOR%')
GROUP BY UNIT_NAME, SUP_EMP_ID) s
WHERE s.SUP_EMP_ID = e.EMP_ID
16. Query 5: SQL Query to calculate numberof hours each employee workedand sort the data in
descendingorderof hours.
SELECT e.F_NAME AS 'First Name', e.L_NAME AS 'Last Name', Total_Hours
FROM EMPLOYEE e, (SELECT EMP_ID, SUM (NUMBER_OF_HOURS) AS 'Total_Hours'
FROM SHIFT_ g, SCHEDULE h, CATEGORY c
WHERE h.SHIFT_ID = g.SHIFT_ID
AND c.CATEGORY_ID = g.CATEGORY_ID
AND CATEGORY_NAME NOT LIKE '%SUPERVISOR%'
GROUP BY EMP_ID) s
WHERE e.EMP_ID = s.EMP_ID
ORDER BY Total_Hours DESC
Query 6: SQL Query to display informationof employeeswithapprovedleaves.
SELECT e.EMP_ID AS 'Emp_Id', e.F_NAME AS 'First Name', e.L_NAME AS 'Last Name', COUNT (l.EMP_ID)
AS 'Leaves Availed'
FROM EMPLOYEE e, LEAVE_DETAILS l
WHERE e.EMP_ID = l.EMP_ID
AND l.REPLACEMENT_FOUND = 'Y'
GROUP BY e.EMP_ID, e.F_NAME, e.L_NAME
Query 7: SQL Query to display informationof employeeswhose leaveswere notapprovedor are
pendingapproval.
SELECT e.EMP_ID AS 'Emp_Id', e.F_NAME AS 'First Name', e.L_NAME AS 'Last Name'
FROM EMPLOYEE e, LEAVE_DETAILS l
17. WHERE e.EMP_ID = l.EMP_ID
AND (l.REPLACEMENT_FOUND = 'N' OR REPLACEMENT_FOUND IS NULL)
GROUP BY e.EMP_ID, e.F_NAME, e.L_NAME
Query 8: SQL Query to calculate the inventoryexpenditure ofeachunit for the monthsof August,
September,October,and November.
SELECT a.UNIT_ID AS 'Id', u.UNIT_NAME AS 'Unit', DATENAME (MONTH, DATE_) AS 'Month_',
SUM (a.COST_PER_UNIT * a.QUANTITY) AS 'Total_Expenditure'
FROM INVENTORY a, UNIT u
WHERE a.UNIT_ID = u.UNIT_ID
GROUP BY a.UNIT_ID, u.UNIT_NAME, DATENAME (MONTH, DATE_)
ORDER BY a.UNIT_ID
Query 9: SQL Query to find pair of total sale values where Unit1 sale is higherthan Unit2.
SELECT U1.UNIT_ID AS 'Unit ID', U1.SALES AS 'Total Sales', U2.UNIT_ID AS 'Unit ID', U2.SALES AS
'Total Sales'
FROM (SELECT UNIT_ID, SUM(AMOUNT) SALES FROM SALES GROUP BY UNIT_ID) U1,
(SELECT UNIT_ID, SUM(AMOUNT) SALES FROM SALES GROUP BY UNIT_ID) U2
WHERE U1.UNIT_ID <> U2.UNIT_ID AND U1.SALES > U2.SALES
18. Query 10: SQL Queryto displayvacancies across differentcategoriesinboth the units.
SELECT v.VACANCY_ID AS 'Id', u.UNIT_NAME AS 'Unit', c.CATEGORY_NAME AS 'Category',
COUNT (DISTINCT(v.SHIFT_ID)) AS 'Number of Positions',
SHIFT_START AS 'Start Time', SHIFT_END AS 'End Time'
FROM UNIT u, CATEGORY c, SHIFT_ s, VACANCY v
WHERE v.SHIFT_ID = s.SHIFT_ID
AND s.UNIT_ID = u.UNIT_ID
AND s.CATEGORY_ID = c.CATEGORY_ID
GROUP BY UNIT_NAME, CATEGORY_NAME, SHIFT_START, SHIFT_END, VACANCY_ID
10.Conclusion
The database system created for the above mentioned coffee shop will manage the details
related to Employees, Shifts, Schedule, Leave, Inventory and Sales for both the units. This
system is more reliable, fast, efficient and user friendly as compared to the excel files that were
being used by the coffee shop management earlier. Also, there is almost no possibility of data
loss while processing. This database system will serve as a useful approach for the management
to handle the employee salary details, leave details, inventory expenditure and vacancies per
unit. Also, being a useful approach, this project will save a lot of time and money for the
concerned management.