-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDMQDogDB.sql
138 lines (70 loc) · 5.64 KB
/
DMQDogDB.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
-- dog queries
-- get all dog columns and name of adopter and food to populate Manage Dogs page and Browse Dogs page
SELECT d.id, name, birthdate, breed, sex, adoptedBy, foodType, image, a.fname, a.lname, f.bname, f.pname FROM Dogs d INNER JOIN Adopters a ON d.adoptedBy = a.id INNER JOIN FoodSupply f ON d.foodType = f.id ORDER BY d.id;
-- get dog id and name to populate dropdown on Works page
SELECT id, name FROM Dogs;
-- get all dog columns for Browse dog page base on search critera
SELECT id, name, birthdate, breed, sex, adoptedBy, foodType, image FROM Dogs WHERE name = :nameInput, birthdate = :birthdateInput, breed = :breedInput, sex = :sexInput, adoptedBy = :adoptedByInputFromDropDown, foodType = :foodTypeInputFromDropDown;
-- add a new dog
INSERT INTO Dogs (name, birthdate, breed, sex, foodType, image) VALUES (:nameInput, :birthdateInput, :breedInput, :sexInput, :foodTypeInputFromDropDown, :imageInput);
-- delete a dog
DELETE FROM Dogs WHERE id = :idSelectedFromManageDogsPage;
-- autopopulate edit dog Page
SELECT name, birthdate, breed, sex, adoptedby, foodtype, image FROM Dogs WHERE id= :idFromEditButton;
-- edit a dog
UPDATE Dogs SET name = :nameInput, birthdate = :birthdateInput, breed = :breedInput, sex = :sexInput, adoptedBy = :adoptedByIDFromDropDown, foodType = :foodTypeIDFromDropDown, image = :imageInput WHERE id = :idFromDogUpdateButton;
-- adopter queries
-- get all adopter columns to populate Adopters page, use count to dynamically populate number of dogs adopted for one-to-many relationship
SELECT Adopters.id, fname, lname, saddress, city, state, zip, phone, COUNT(d.id) as nad FROM Adopters LEFT JOIN Dogs d ON Adopters.id = d.adoptedBy GROUP BY Adopters.id;
-- get adopter id, fname, and lname columns in Adopters to populate a dropdown for searching by adopter on Browse Dogs page and edit dog page
SELECT id, fname, lname FROM Adopters;
-- add a new adopter
INSERT INTO Adopters (fname, lname, saddress, city, state, zip, phone) VALUES (:fnameInput, :lnameInput, :saddressInput, :cityInput, :stateInput, :zipInput, :phoneInput);
-- delete an adopter
DELETE FROM Adopters WHERE id = :idSelectedfromAdoptersPage;
-- autopopulate adopter edit page
SELECT fname, lname, saddress, city, state, zip, phone FROM Adopters WHERE id = :idFromEditButton;
-- edit an adopter
UPDATE Adopters SET fname = :fnameInput, lname = :lnameInput, saddress = :saddressInput, city = :cityInput, state = :stateInput, zip = :zipInput, phone = :phoneInput WHERE id = idFromAdopterEditButton;
-- Employee queries
-- get all Employee columns to populate Employee page
SELECT id, fname, lname, fsa, phone, title, IF(fsa = 1, 'Yes', 'No') as auth FROM Employees;
-- get employeeID, fname, lname columns of only employes able to order food to populate dropdown on Food Orders page
SELECT id, fname, lname FROM Employees WHERE fsa = TRUE;
-- get employeeID, fname, lname clumns of employess to populate dropdown on Works page
SELECT id, fname, lname FROM Employees;
-- add a new Employee
INSERT INTO Employees (fname, lname, fsa, phone, title) VALUES (:fnameInput, :lnameInput, :fsaInput, :phoneInput, :titleInput);
-- delete an employee
DELETE FROM Employees WHERE id = :idSelectedFromEmployeePage;
-- autopopulate edit employee page;
SELECT id, fname, lname, fsa, phone, title, IF(fsa = 1, 'Yes', 'No') as auth FROM Employees WHERE id=:idFromEditButton;
-- Edit an employee
UPDATE Employees SET fname = :fnameInput, lname = :lnameInput, fsa = :fsaInput, phone = :phoneInput, title = :titleInput WHERE id = :idFromEmployeeEditButton;
-- Food Supply Queries
-- get all columns from FoodSupply to populate Food Supply Page, use count to dynamically calculated the number of dogs on a food type
SELECT f.id, bname, pname, COUNT(d.id) AS numberd, amount FROM FoodSupply f LEFT JOIN Dogs d ON f.id = d.foodType GROUP BY f.id
-- get id, bname, and lname from FoodSupply to populate dropdowns on Order Food Page and Manage Dog page
SELECT id, bname, pname FROM FoodSupply;
-- add a new Food Supply
INSERT INTO FoodSupply (bname, pname) VALUES (:bnameInput, :pnameInput);
-- delete a food supply
DELETE FROM FoodSupply WHERE id = :idSelectedFromFoodSupplyPage;
-- autopopulate food supply edit page
SELECT bname, pname, quantity FROM FoodSupply WHERE id = :idFromEditButton;
-- edit food supply
UPDATE FoodSupply SET bname = :bnameInput, pname = :pnameInput, quantity = :amountInput WHERE id = :idFromFoodSupplyEditButton;
-- food order queries
-- add a new Food order
INSERT INTO Orders (FoodSupplyID, EmployeeID, quantity) VALUES (:foodInputFromDropDown, :idInput, :quantityInput);
-- delete from food order (M-to-N relationship)
DELETE FROM Orders WHERE EmployeeID = :pidSelectedFromOrdersPage and FoodSupplyID = :fidSelectedFromOrdersPage;
-- get employee id, fname, lname, and foodsupply bname, pname, and orders quantity and date ordered to display on Food Orders page
SELECT Employees.id as eid, fname, lname, FoodSupply.id as fid, bname, pname, Orders.quantity, DATE_FORMAT(dateOrdered, '%Y-%m-%d %H:%i:%s') AS newDate FROM Employees INNER JOIN Orders ON Employees.id = Orders.EmployeeID INNER JOIN FoodSupply ON FoodSupply.id = Orders.FoodSupplyID ORDER BY Orders.dateOrdered;
-- Work Queries
-- add a new work relationship
INSERT IGNORE INTO Works (EmployeeID, DogID) VALUES (:pidInput, :didInput);
-- delete from works (M-to-N relationship)
DELETE FROM Works WHERE EmployeeID = :pidSelectedFromWorksPage and DogID = :didSelectedFromWorksPage;
-- get employee id, fname, lname and dog id, name to display on Works Page
SELECT Employees.id, fname, lname, title, Dogs.id, name FROM Employees INNER JOIN Works ON Employees.id = Works.EmployeeID INNER JOIN Dogs ON Dogs.id = Works.DogID;